问题描述
我一直在忙于执行cron作业,到目前为止,我无法使其正常工作。
以下是命令:
docker exec mosquitto mosquitto_pub -h localhost -p 1883 -u LOGIN -P PASSWORD -t rtorrent_ntorrents -m "{\"ntorrents\": $(docker exec -it box rtxmlrpc download_list "" | wc -l)}"
这是我尝试过的:
- 将其放入每分钟执行一次的cronjob中:
* * * * * /usr/bin/zsh -c 'docker exec mosquitto mosquitto_pub -h localhost -p 1883 -u LOGIN -P PASSWORD -t rtorrent_ntorrents -m "{\"ntorrents\": $(docker exec -it box rtxmlrpc download_list "" | wc -l)}"'
->失败
-
将命令放入
.zshenv
或.zshrc
中的函数中,然后创建一个启动该函数的CRON作业->失败 -
我还尝试设置一个简单的脚本:
#!/usr/bin/zsh
while :
do
docker exec mosquitto mosquitto_pub -h localhost -p 1883 -u LOGIN -P PASSWORD -t rtorrent_ntorrents -m "{\"ntorrents\": $(docker exec -it box rtxmlrpc downl$
sleep 60
done
哪种方式失败:
[1] 8665
[1] + 8665 suspended (tty output) ./ntorrents
我发现在后台进程中使用命令的 only 方法是screen
...
当然,在外壳中运行命令本身会产生所需的结果。
预先感谢您的帮助。
解决方法
如评论中所述,删除-it
参数可以解决此问题。