my cronjob does not start

james80

Member
Joined
Jan 17, 2021
Messages
42
Reaction score
5
Credits
315
Hi,

using Debian and I want to use a cronjob to backup, I did some testings to learn cronjob but it did work.
Here my exemple:

0 17 * * * tar -zcf /home/james/Documents.tgz /media/james/E/backup

If I want to backup my Documents folder everyday @5pm, is it ok? Cause it does not work
thanks
 


I would really recommend calling a script of some kind from /etc/crontab instead of providing the arguments there.

Use journalctl -xe to check to make sure the system is re-reading your crontab file after you edit it and see if it holds any clues or complaints. Also, cron sends email to the mail user instead of the root user so check the mail for any command output. Use mail -u mail to check the email for the mail user.

Using /media/james/E/backup will store that absolute path in your tar file. I would recommend moving to the root directory and using /usr/bin/tar -cf /backup/james/Documents.tar media/james/E/backup and then call gzip afterwards. Make sure to test your zipped tar archive file with gzip -t after that.

Signed,

Matthew Campbell
 
I dont understand ? I dont know about that

Instead of putting the command in cron.
i.e.
Code:
0 17 * * * tar -zcf /home/james/Documents.tgz /media/james/E/backup

Do this instead. You can do do this in your home directory.
Create a bash shell script that looks like this. Name it something like james_tar_backup.sh

Code:
#!/bin/bash
tar -zcf /home/james/Documents.tgz /media/james/E/backup

Make it executable.
Code:
chmod +x james_tar_backup.sh

Now change your cron job to this.
Code:
0 17 * * * /home/james/james_tar_backup.sh

It's good idea to test your shell script before you put it in cron. You can just run it from the command line.

Code:
./james_tar_backup.sh

and see if it works or gives an error before adding it to your cron job.

Also depending on your distro. You can look at...
Code:
cat /var/log/cron
or
Code:
cat /var/log/cron.log
 

Staff online


Top