例子:sgrep.sh “查找的字符串” [文件名全称]
#!/bin/bash
#echo "app name is $1"
condition=$1
filePath=$2
app_name="crmtask_236_1"
g_operation="sgrep"
user="crmtask1"
host="132.126.2.236"
passwd="XXXX"
libPath="/data/crm/crmtask1/tomcat/webapps/crmtask/WEB-INF/lib"
myLogPath="${libPath/%WEB-INF\/lib/myLog}"
expect << EOF
set timeout 2
spawn ssh ${hostInfo}
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" {send "${password}\r";exp_continue}
"Permission denied*" {send_user "invalid password or account\n";exit}
}
expect "]*"
send "cd ${myLogPath}\r"
send "grep \"${condition}\" ${filePath}\r"
send "exit\r"
expect eof
EOF
echo "sgrep $1 over!"