Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to schedule this backup job using CRON. The test I tried before in which I just scheduled an email to be sent worked fine. But no such luck here.
Here is what I did:
1) I created a file called backup.sh in the /etc/cron.daily folder, which had this as its contents:
#!/bin/bash
tar -czvf /backupdirectory/backup.tgz /directorytobackup
2) I installed this cron job in crontab:
12,32 * * * * /etc/cron.daily/backup.sh
Am I placing the backup.sh file in the wrong directory? Also, do I need to create an .sh file at all? Can't I just put the backup command right in the cron job instead of calling to the backup.sh file?
Scripts in the /etc/cron.daily folder are run by cron automatically once a day (usually at 4 AM). You're right, you can just have a crontab entry that looks like:
12,32 * * * * tar -czvf <whatever> <whatever>
in your crontab. If you want a backup, I suggest adding the -p flag to tar to tell it to preserve permissions (you'll need to be root for this to work if there are files not owned by you).
Don't if what you posted was a typo but 12 32 * * * is invalid.
FIELD VALUE
------------------
minute 00 to 59
hour 00 to 23 (military time)
day 1 to 31
month 1 to 12
weekday 0 to 6 (0=Sunday) Note: Linux uses sun, mon...
The syntax you gave tells it to execute at 3:25 PM every day. So it should've executed today. For sanity's sake make sure crond is running and chack your cron log in case there were errors (it should be in /var/log/cron). Also, you might want to provide the full path to tar just to be safe.
I didn't understand what you meaned by "I scheduled and installed". By the manual, all you have to do is enter "crontab -e" as the user owner of that queue. crontab will open your preferred editor for you to edit the job. When you save the edit and close the editor, it does a consistency test of the jobs and submit to the cron queue. You can see the scheduled jobs with "crontab -l".
Oddly, the backup actually ran - precisely an hour after I scheduled it. It was scheduled for 4:35 in the Cron Job and ran at 5:35 instead. To test this, I just scheduled a job for 7:30 in crontab and it ran at 8:30.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.