expect自动检测并重启另外一台服务器上的程序代码
[s005 you] # cat haproxy_expect
#!/usr/bin/expect
set ssh_user "fivetrees"
set password "123456"
spawn ssh -i /root/.ssh/$ssh_user Server004.xd.com
expect_before "no)?" {
send "yesr" }
sleep 0.5
expect "Enter passphrase for key*"
send "$passwordr"
expect "*#"
send "/tmp/haproxy.shr"
expect "*#"
send "echor"
exit
[s004 him] # cat haproxy.sh
#!/bin/bash
Thread=`ps -ef | grep haproxy | grep -v haproxy.sh | grep -v grep`
if [ -z "$Thread" ]
then
/tmp/haproxy_expect
fi
[s004 him] # cat haproxy_expect
#!/usr/bin/expect
set ssh_user "fivetrees"
set password "123456"
spawn ssh -i /root/.ssh/$ssh_user Server005.xd.com
expect_before "no)?" {
send "yesr" }
sleep 0.5
expect "Enter passphrase for key*"
send "$passwordr"
expect "*#"
send "/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfgr"
expect "*#"
send "echor"
exit
shell查找当前目录下大于1M的文件的三种方法分享
1、使用find的参数实现[root@xiaobbmnt]#find.-maxdepth1-size+1000000c./sys.tar.gz./install.tar.bz2./CTeX_2.9.0.152_Full.exe./php-5.3.6.tar.gz[root@xiaobbmnt]#ls-lhtotal1.3G-rw-r--r--1rootroot1.1
awk统计文件中某关键词出现次数的命令
awk-F""'{for(i=1;i=NF;++i)if($i=="a")++sum}END{printsum}'test.c[root@xiaobb5906]#awk'{for(i=1;i=NF;++i)if($i=="test")++sum}END{printsum}'test.c6[root@xiaobb5906]#cattest.ctesttestktesttestatesttestalt
shell 进度条实现代码
#!/bin/bashCOUNTER=0_R=0_C=`tputcols`_PROCEC=`tputcols`tputcup$_C$_Rprintf"["while[$COUNTER-lt100]doCOUNTER=`expr$COUNTER+1`sleep0.1printf"="_R=`expr$_R+1`_C=`expr$_C+1`tputcup$_PROCEC101printf"]%d%%"