最近在做一個檢測腳本,併發送日誌到相關服務器。腳本測試正常,且日誌發送正常,遂加入crontab
但是在crontab中無法,執行。逐一檢查crontab運行狀態、腳本執行權限、環境變量等等,均正常,腳本還是無法執行。
後來發現一帖子,說scp.exp有問題
如下爲:scp.exp
#!/usr/bin/expect -f
set CMD0 [lindex $argv 0]
set CMD1 [lindex $argv 1]
set PASS "dawa@2013"
spawn scp -r $CMD0 $CMD1
set timeout 10
expect {
"*(yes/no)*" { send "yes\r" }
"*password*" { send "${PASS}\r" }
}
interact
最後scp.exp停留在交互上,而密碼無法輸入,一直失敗。必須終止交互
遂修改scp.exp成功
修改如下
#!/usr/bin/expect -f
set CMD0 [lindex $argv 0]
set CMD1 [lindex $argv 1]
set PASS "dawa@2013"
spawn scp -r $CMD0 $CMD1
expect {
"*(yes/no)*" { send "yes\r" }
"*password*" { send "${PASS}\r" }
}
#interact
set timeout 20
expect eof
exit