是否有一种特殊的方法来收集/home/casper/autoEXPscp.sh的退出状态。因为调试模式是说退出状态为零,但文件不是Ftp' d。
#!/bin/bash
set -x
blmnt="/home/casper/BlueMountain/"
ydate=$(date -d 'yesterday' "+%Y.%m.%d")
bfile="casper_BlueMountain_${ydate}.csv"
cd $blmnt
if [[ -e ${blmnt}${bfile} ]]; then
/home/casper/autoEXPscp.sh
result=$?
if [ $result -eq 0 ]; then
echo "Bluemountain scp is successful"
else
echo "Bluemountain scp failed"
fi
else
echo "${blmnt}${bfile} was not created "
exit 1
fi
#!/usr/bin/expect
set ydate [exec date -d "yesterday" "+%Y.%m.%d"]
set file "casper_BlueMountain_${ydate}.csv"
spawn scp -o StrictHostKeyChecking=no -oport=56050 $file casper@casper.com:/bluemountain/outgoing
set pass "foo"
expect {
password: {send "$pass\r"; exp_continue}
}
答案 0 :(得分:0)
也许:
#!/usr/bin/expect
set ydate [clock format [clock add [clock seconds] -1 day] "%Y.%m.%d"]
set file "casper_BlueMountain_${ydate}.csv"
set timeout -1
spawn scp -o StrictHostKeyChecking=no -oport=56050 $file casper@casper.com:/bluemountain/outgoing
set pass "foo"
expect {password:}
send "$pass\r"
expect eof
lassign [wait] pid spawnid flag status
exit $status
注释:
clock
command expect eof
)
wait
命令获取退出状态。请参阅expect(1)
man page