Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: Shell script not running from cron?
#1
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
Transferred:              0 B / 0 B, -, 0 B/s, ETA -
Checks:              7041 / 7041, 100%
Elapsed time:        36.8s
music@music:~/rclone $


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
● cron.service - Regular background program processing daemon
    Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: >
    Active: active (running) since Sun 2024-10-27 21:31:50 GMT; 23h ago
      Docs: man:cron(8)
  Main PID: 30121 (cron)
     Tasks: 1 (limit: 2057)
       CPU: 13.196s
    CGroup: /system.slice/cron.service
            └─30121 /usr/sbin/cron -f

Oct 28 20:35:01 music CRON[30809]: pam_unix(cron:session): session closed for u>
Oct 28 20:39:01 music CRON[31278]: pam_unix(cron:session): session opened for u>
Oct 28 20:39:01 music CRON[31279]: (root) CMD (  [ -x /usr/lib/php/sessionclean>
Oct 28 20:39:01 music CRON[31278]: pam_unix(cron:session): session closed for u>
Oct 28 20:45:01 music CRON[31981]: pam_unix(cron:session): session opened for u>
Oct 28 20:45:01 music CRON[31982]: (root) CMD (command -v debian-sa1 > /dev/nul>
Oct 28 20:45:01 music CRON[31981]: pam_unix(cron:session): session closed for u>
Oct 28 20:55:01 music CRON[767]: pam_unix(cron:session): session opened for use>
Oct 28 20:55:01 music CRON[768]: (root) CMD (command -v debian-sa1 > /dev/null >
Oct 28 20:55:01 music CRON[767]: pam_unix(cron:session): session closed for use>
lines 1-20/20 (END)

but my automatic backup doesn't run. What am I missing here?
Reply
#2
Try

sudo sytemctl enable cron
sudo reboot
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Thanks, have done that and will report back :-)
Reply
#4
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
Transferred:             35 B / 35 B, 100%, 0 B/s, ETA 0s
Checks:              7041 / 7041, 100%
Transferred:            1 / 1, 100%
Elapsed time:        36.1s
music@music:~/rclone $


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.
Reply
#5
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
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
 rclone
0 upgraded, 1 newly installed, 0 to remove and 12 not upgraded.
Need to get 13.0 MB of archives.
After this operation, 57.2 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 rclone arm64 1.60.1+dfsg-2+b5 [13.0 MB]
Fetched 13.0 MB in 2s (7,407 kB/s)
Selecting previously unselected package rclone.
(Reading database ... 84533 files and directories currently installed.)
Preparing to unpack .../rclone_1.60.1+dfsg-2+b5_arm64.deb ...
Unpacking rclone (1.60.1+dfsg-2+b5) ...######.............................................................................................................]
Setting up rclone (1.60.1+dfsg-2+b5) ...################################..................................................................................]
Processing triggers for man-db (2.11.2-2) ...#################################################################################............................]
pi@moode9:~ $
pi@moode9:~ $ which rclone
/usr/bin/rclone
pi@moode9:~ $
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
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!
Reply
#7
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!
Reply


Forum Jump: