1)安裝expect
[root@server ~]# yum install -y expect
2)編寫腳本
#!/usr/bin/expect -f
#created by mis_yw 2013-11-30
#verify virus by system user oa
#set password [1index $argv 0 ]
#set timeout 10.
set file [ lindex $argv 0 ]
spawn su -c "/opt/kaspersky/kav4fs/bin/kav4fs-control --scan-file $file" root
expect {
"*Password:" {send "XXXXXX\r"}
}
interact
#!/bin/sh
#created by mis_yw 2013-11-30
#verify virus.
file=$1
if [[ ! -e $file ]] ;then
#echo "$file is not exsit."
echo no
exit 0
fi
infected=`./verifyvirus $file | grep Infected | grep 0`
if(($?)) ;then
echo yes
else
echo no
fi