红字部分为使用expect和如何与shell进行参数交互。
参数交互就是用个系统变量来做~~
#!/bin/bash
ARGV="$1"Method="$2"
if [ -z $Method ]
then
Method=2
fi
if [ -z $ARGV ]
then
echo "Need args"
exit
fi
rm $ARGV
scpPath="/root/$ARGV"
export file=$scpPath
echo "puts $env($file)"
/usr/bin/expect << \EOF
set timeout 3600
set pwd xxxxxx
spawn scp root@172.25.40.52:$env(file) ./
expect "*word:"
send "$pwd"
send "\r\n"
expect eof
EOF
/bin/bash << \EOF
#2>1 | grep password | echo pass
chmod +x *
index=''
while [ -z $index ]
do
index=$(/usr/local/apache2/bin/apachectl stop | awk '{print $1}')
echo $index
sleep 1
done