我有这个简单的脚本,记录比特币的汇率。我发现每隔几天脚本就会停止。为了保持这种状态,我在无限循环之后立即调用了脚本本身,但我想知道为什么它会退出。谢谢你的提示。
#!/bin/bash
# logfile
logfile=/var/log/bitcoin_log
# frequency of updates, in minutes
sleepmins=1
# url of the bitcoin exchange rates
url=https://blockchain.info/it/ticker
# timeout
timeout=120
# number of bitcoins
balance=1
let sleepsecs=$sleepmins*60
#infinite loop
while true
do
eur=`curl -m $timeout -s $url | grep EUR | awk '{print $11}'`
eur=${eur::-1}
eurwall=`echo $eur*$balance | bc`
echo `date --rfc-3339=seconds`' '$eur' '$eurwall >> $logfile
sleep $sleepsecs
done
# if the script breaks out of the infinite loop, write to the log and restart it
echo `date --rfc-3339=seconds`' '$0' pid '$$': exited the infinite loop' >> \
$logfile
./btcwallet &