【脚本】shell去掉最后一个字符
Linux 局域网ping脚本,检查主机是否在线。
同目录下建立hosts.txt文件,写上要ping的主机ip
执行脚本如下ping_hosts.sh
#!/bin/bash #2011/11/22 #Jiaozn #ping hosts file="hosts.txt" for host_ip in $(cat $file) do i=`ping -c 3 $host_ip |grep '3 received'|wc -l` if [ $i -ne 1 ] then echo $host_ip not ping. fi done
#Git和ssh验证方面可以使用下面的方法
yum -y install expect
cat > expect.sh <<EOF
#!/usr/bin/expect -f
set timeout 30
spawn git pull origin maste
expect {
"*yes/no"
近来需要写个小shell判断用户输入的字符串是否为有效的ip地址,简单排除了以下几种情况:
1. 以点号为分隔的域不等于4或6;
2. 出现字符;
3. 某域以0开头;
4. 各域数值长度大于3;
5. 各域数值大于255
6. 第一个和最后一个域为0
IPADDR=192.168.1.1 (有效)
IPADDR=192.168.0.254(有效)
IPADDR=10.0.0.0(无效)
#!/bin/bash # bak file 7 day logs_dir=/data bak_dit=/backup bak_file=access_`date+%Y%m%d`.log #tar everyday #echo "begining of tar" tar zcf $bak_