![]() |
[SOLVED] Shell script not running from cron? - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7) +--- Thread: [SOLVED] Shell script not running from cron? (/showthread.php?tid=7044) |
Shell script not running from cron? - stymaster - 10-28-2024 Hi everyone. I've been using 8.3.9 on an RPi 2 for a while, and I'm loving it, beautiful interface, nice functionality. I have one issue that I've found someone kid-of asked before https://moodeaudio.org/forum/showthread.php?tid=6312&highlight=cron. I'm using rclone to sync my music to Google drive after I once broke the external USB drive it lives on and had to rip most of it again. The shell script I use is /home/music/rclone/rclone-copy.sh and running that interactively as the logged-on user "music" works just fine: Code: music@music:~/rclone $ /home/music/rclone/rclone-copy.sh and I've added the script in with crontab -e: Code: 0 3 * * * /home/music/rclone/rclone-copy.sh > /dev/null I also found that cron didn't seen to be started so I did "service start cron" and "service enable cron" and cron seems to be running: Code: music@music:~/rclone $ service cron status but my automatic backup doesn't run. What am I missing here? RE: Shell script not running from cron? - Tim Curtis - 10-28-2024 Try sudo sytemctl enable cron sudo reboot RE: Shell script not running from cron? - stymaster - 10-28-2024 Thanks, have done that and will report back :-) RE: Shell script not running from cron? - stymaster - 10-29-2024 So, I left my crontab as it was (3am), and dropped a text file into the music folder to see if it copied overnight. It didn't. My next step was to edit the cron entry to this: Code: */5 * * * * /home/music/rclone/rclone-copy.sh > /home/music/cronlog.txt So every 5 minutes and output redirect to cronlog.txt. The cronlog.txt file is created, but is empty. So clearly the cron job is triggered, at least. This proves that cron is running and that my crontab works. I next edited my shell script and told rclone to log to a file: Code: ./rclone --log-file=/home/music/rclone/log.txt -v copy -P /media/F4C6-C445/music gdrive:music That logfile is also empty :-( Running the script interactively did what i expected and copied the file, outputting progress to the terminal. Code: music@music:~/rclone $ ./rclone-copy.sh Not sure what is going on here. One additional thing- when my music player was rAudio, this worked from cron. Now, this isn't a huge problem, it's no great hardship to log in to the shell and run the backup once in a while, but I'm curious as to why it doesn't work, and what else I can to to troubleshoot it. RE: Shell script not running from cron? - Tim Curtis - 10-29-2024 Sounds like some sort of permissions problem with the rclone binary especially since it's being run via ./rclone instead of just rclone. I'm not sure how you installed it but typically it would be installed via standard apt like below and the binary would be in /usr/bin which is always in the global path so no need for specific path to it. Code: pi@moode9:~ $ sudo apt -y install rclone RE: Shell script not running from cron? - stymaster - 10-29-2024 Ah, that sounds well worth a try. The answer is that I just copied over the binary, complete with the config file, and ran it. The reason I did that was that I'd had it working on rAudio (which is Arch-based), it *seemed* to work after a chomd +x, I wasn't familiar with Arch package management, and there was a handy download at https://rclone.org/downloads/. As it happens, I'm a lot more familiar with Debian package management (using Ubuntu right now) so I'll try installing rclone properly and see if that behaves. Thanks! RE: Shell script not running from cron? - stymaster - 10-29-2024 Success! I installed rclone with apt, and my shell script is now Code: rclone --config=/home/music/rclone/rclone.conf copy -P /media/F4C6-C445/music gdrive:music The file copies successfully. Thanks for your assistance! |