我什至包含source /home/user/.bashrc; <my scripts>
在 crontab 中,但它仍然没有输出正确的东西。
我的脚本中有一个 while 循环,它检查来自名为 zend 的服务的一些值。它就像比特币,但对于 Zen。函数看起来是这样的,我把它放在这里 check_existing_balance_withoutfl
应该大于 0 但它是说当我从 cron 运行时它是 0。
{
declare -i bal;
bal=0
while [ $bal -le 1 ]
do
# #code to send zen to z addresses
echo "Balance is $check_t_balance";
logger "Balance is $check_t_balance";
sleep 5
# This following line is essential at this particular place
export_address=$(zen-cli listaddresses | jq -r '.[2]');
if python -c "import sys; sys.exit(0 if float($check_t_balance) <= float($min_ask_zen) else 1)"; # # for test
# # if python -c "import sys; sys.exit(0 if float($check_t_balance) >= float($min_ask_zen) else 1)";
# if [ $(bc <<< "$check_t_balance >= $min_ask_zen") -eq 1 ];
then
#statements
echo "ZEN balance is sufficient"
echo
echo "We have received $check_t_balance zen in $export_address this t address"
echo
echo "Now, this will be sent to two z-addresses" && echo
logger "Now, this will be sent to two z-addresses" && echo
# # Recommended tx_fee is >= 0.0001
# # Increse here if needed
# tx_fee=0.0001;
amt_aft_txfee=$(python -c "print(float($check_t_balance-$tx_fee))");
amt=$(python -c "print(float($amt_aft_txfee/2))");
echo "Sending now.... $amt ZEN to two z addresses"
topUpzksnark;
# # zen-cli z_sendmany $new_imported_address '[{"address": "'$(zen-cli z_getnewaddress)'", "amount": $amt},{"address": "'$(zen-cli z_getnewaddress)'", "amount": $amt}]';
echo "$amt ZEN is sent to two Z addresses"
else
echo "ZEN balance is not suffiecient"
moreZentoSend=$(python -c "print(float($min_ask_zen-$check_t_balance))")
echo "Please send at least $moreZentoSend Zen to $export_address this address" >> /home/rock64/log.txt
logger "Please send at least "$moreZentoSend" Zen to "$export_address" this address"
echo "bal is $bal" >> /home/rock64/log.txt
fi
declare -i bal;
declare -i check_existing_balance_withoutfl;
echo "check_existing_balance_withoutfl is $check_existing_balance_withoutfl" >>/home/rock64/log.txt;
check_existing_balance_withoutfl=$(zen-cli z_gettotalbalance | grep total | tr -d '," ' | cut -d ':' -f2 | tr -d '.' | bc);
# check_existing_balance_withoutfl=$((10#$(zen-cli z_gettotalbalance | grep total | tr -d '," ' | cut -d ':' -f2 | tr -d '.')));
# check_existing_balance_withoutfl=$((10#$check_existing_balance_withoutfl));
bal+=$check_existing_balance_withoutfl;
echo "check_existing_balance_withoutfl is $check_existing_balance_withoutfl" >>/home/rock64/log.txt;
echo "bal is $bal after if else" >>/home/rock64/log.txt
done
}
sudo crontab -e
与55 8 * * * source /home/rock64/.bashrc; /home/rock64/light.sh > /home/rock64/both.log 2>&1
>一起使用时的日志
check_existing_balance_withoutfl is 0
bal is 0 after if else
There is not enough balance in the node T Address
check_existing_balance_withoutfl is 0
check_existing_balance_withoutfl is 0
bal is 0 after if else
如果我不是从 crontab 运行脚本,则一切正常。
$ check_existing_balance_withoutfl=$(zen-cli z_gettotalbalance | grep total | tr -d '," ' | cut -d ':' -f2 | tr -d '.' | bc)
rock64@cheese:~$ echo $check_existing_balance_withoutfl
498
为什么 bal 从 cron 执行时不是 498?我真的不知道,我做错了什么。
bash -x
按照@Marcel 的建议查看日志后,我似乎发现了问题。因为,我把我的脚本放在了sudo crontab -e
,它指的是 /home/root/.zen 目录中的一个配置文件,所以对于 zend 客户端,我必须用我的脚本中的所有zen-cli
行替换zen-cli -conf=/home/user/.zen/zen.conf
。同样适用于bitcoind
,如果有人想放入bitcoin-cli
crontab 来检查一些特定的事务或其他什么。
bash -x
按照@Marcel 的建议查看日志后,我似乎发现了问题。因为,我把我的脚本放在了
sudo crontab -e
,它指的是/home/root/.zen
目录中的一个配置文件。因此,
zend
要让客户在其下工作,sudo crontab -e
或者/etc/crontab
我必须用我的脚本中的所有zen-cli
行替换zen-cli -conf=/home/<yourusername>/.zen/zen.conf
。同样适用于bitcoind
,不要使用
$USER
in ,<yourusername>
因为它将是 root 下的sudo crontab -e
,因此请使用用户的全名或在变量中指定用户名。如果有人想
bitcoin-cli
在sudo crontab -e
系统启动或任何其他功能期间检查某些特定交易或需要密码的东西,您可以替换bitcoin-cli
和bitcoin-cli -conf=/home/<yourusername>/.bitcoin/bitcoin.conf
因此,例如检查最新块而不是做
bitcoin-cli getblockcount
做:bitcoin-cli -conf=/home/<yourusername>/.bitcoin/bitcoin.conf getblockcount