我做了這個腳本來檢查以確保創建了離岸腳本。我工作正常&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 ++))'來控制循環。 –