Cron task based on command line tasks.



  • I always fight with this, and today is no different. I have a command that I run at the command line and it works perfectly. However, I cannot get it to run as a cron job, and don't have any idea where to look for problems (logs) to even begin to troubleshoot. I know I can turn my one liner into a shell script, and cron that, but it has become a challenge for me to figure out how to write complex cron tasks.

    Here is what I run at the command line:

    /usr/bin/mysqldump -u root -prootpassword nextcloud > /tmp/nextcloud.sql; sudo 7z a -pencryptionpassword  /tmp/nextcloud.7z /tmp/nextcloud.sql /var/www/nextcloud/config/config.php; echo "Today's backup of the My Nextcloud SQL Data is attached." | /usr/bin/mailx -A /tmp/nextcloud.7z -s "Cloud.example.Com Nextcloud SQL Backup" -r "[email protected]" [email protected]
    

    Any helpful ideas from those smarter than me?



  • @JasGot said in Cron task based on command line tasks.:

    I know I can turn my one liner into a shell script, and cron that, but it has become a challenge for me to figure out how to write complex cron tasks.

    You make it a script. Cron tasks have to always be simple. Single command, don't let any complexity creep into the cron area.



  • @JasGot said in Cron task based on command line tasks.:

    #!/bin/bash
    /usr/bin/mysqldump -u root -prootpassword nextcloud > /tmp/nextcloud.sql 
    7z a -pencryptionpassword  /tmp/nextcloud.7z /tmp/nextcloud.sql /var/www/nextcloud/config/config.php
    echo "Today's backup of the My Nextcloud SQL Data is attached." | /usr/bin/mailx -A /tmp/nextcloud.7z -s "Cloud.example.Com Nextcloud SQL Backup" -r "[email protected]" [email protected]
    

    Make that a file, run with cron.


Log in to reply