Search code examples
dockercronrpc

Long CRON command does not work, no matter how I use it


I've been fiddling a lot with a cron job, and so far I cannot make it work properly.

Here is the command:

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)}"

Here is what I tried:

  • putting it in a cronjob to be executed every minute:
* * * * * /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)}"'

-> fails

  • put the command in a function in .zshenv or .zshrc, then create a CRON job launching the function -> fails

  • I also tried setting up a simple script:

#!/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

Which fails this way:

[1] 8665
[1]  + 8665 suspended (tty output)  ./ntorrents

The only way I found to use my command in a background process is screen...

Of course, running the command itself in a shell produces the desired result.

Thanks in advance for your help.


Solution

  • As mentioned in the comments, removing the -it parameter solves the issue.