How to Fix Shell Script Failing in Crontab While Running Manually

       Today, while backing up system directory files, I ran into a problem: the .sh script file could be executed manually, but when added to a cron job, it would exit after compressing the backup file to a certain size.
      After searching online, I finally found the answer. The solution is as follows:
My original cron entry looked like this:
30 3 * * * /home/backup/glassfish3.sh
After the change, it looks like this:
30 3 * * * /home/backup/glassfish3.sh >> /home/backup/error.log 2>&1     

This essentially outputs a log file.
Of course, if we don’t need this file, we can simply add rm -r -r   /home

Leave a Comment

Your email address will not be published.