我做了这个脚本来检查以确保创建了离岸脚本。我工作正常&emdash;我加入了一个使它更清洁的功能。但我不认为这个功能可以工作,因为它可以在几秒钟内同时打印出来。在while循环中调用Bash函数
#!/bin/bash
#set -x
check_offshore()
{
local RESULTS
RESULTS=$(ssh -q -T [email protected] "ls -ltr /come/and/play/with/us/danny/DropBox| grep foreverr_and_$today.csv")
rc=$?
}
today=$(/bin/date +%Y%m%d)
time=$(/bin/date +"%T.%3N")
iterate=0
while [ $iterate -le 5 ]
do
check_offshore
if [[ $rc != 0 ]] ; then
echo "$time foreverr_and_$today.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox"
fi
sleep 5
iterate=$((iterate+1))
done
这是它创建的日志&emdash;日志时间永远不会改变。它一直保持不变,直到剧本停止。
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
17:42:28.380 foreverr_and_20150102.csv is not present in [email protected]:/come/and/play/with/us/danny/DropBox
这是怎么回事,我该如何解决它?
既然你没有在循环内设置'time = $(...)',你怎么期望它改变呢? –
如果你使用Bash,你可能更喜欢'((iterate = 0; iterate <= 5; iterate ++))'来控制循环。 –