Friday, May 17, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2713  / 1 Year ago, sat, december 10, 2022, 4:47:49

I created a cron job as root with the command:



crontab -e


Then I added 0 4 24-31 * 4 /home/backupscript.sh after the last line.



The output of crontab -e looks like this:



# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 4 24-31 * 4 /home/backupscript.sh


My script at /home/backupscript.sh looks like this:



cd "/home/backups/"
datestring="$(date +%Y-%m-%d)"
sudo /opt/bitnami/ctlscript.sh stop
sudo tar -pczvf ${datestring}.openproject-backup.tar.gz /opt/bitnami
sudo /opt/bitnami/ctlscript.sh start


It works fine when I run it with bash /home/backupscript.sh.


More From » command-line

 Answers
7

Make sure your script has set the execute flag when executing it directly or use bash as interpreter with the script as input.



To use bash as interpreter change the line to 0 4 24-31 * 4 bash /home/backupscript.sh



To set the execute flag for the script use: chmod +x /home/backupscript.sh


[#14783] Sunday, December 11, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
njuash

Total Points: 402
Total Questions: 125
Total Answers: 98

Location: Jersey
Member since Sun, Dec 4, 2022
1 Year ago
;