Solved rsync and crontab

Solved issue

james80

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


I use a script to backup my home directory and now I want to add it to a cronjob but it does not work yet.


here my crontab setup;
Code:
0 23 * * * sh /home/james/rsync_backup.sh

I really don't know why it does not start?

thanks
 
Last edited:


What is the error when you run the shell script?
 
What is the error when you run the shell script?
no error during the script, the problem is about cronjob, nothing happens. Maybe cause I use sudo during script?

EDIT: I saw that error:
Code:
pam_unix(sudo:auth): conversation failed
Feb 03 17:01:01 ninja sudo[13488]: pam_unix(sudo:auth): auth could not identify password for [james]
 
Last edited:
What happens when you try to run your script directly from the command line? Does it work? You should always make sure your stuff works that way first before using it as a cron job.

Signed,

Matthew Campbell
 
What happens when you try to run your script directly from the command line? Does it work? You should always make sure your stuff works that way first before using it as a cron job.

Signed,

Matthew Campbell
yes working great, but it asks me my password with sudo.
 
You can take a look at this...


There is a section about password-less sudo commands.
 
There is a section about password-less sudo commands.
ok thanks, but if I want that crontab execute my script without password, I have to use that :
Code:
bob ALL=(ALL) NOPASSWD: ALL
?

I could you something like that :
Code:
user ALL= NOPASSWD:/usr/bin/rsync  or user ALL= NOPASSWD:/home/james/rsync
 
ok thanks, but if I want that crontab execute my script without password, I have to use that :

It's not the only way, but it's the easiest way. Rememebr to change the name from bob, to whoever you login as.
 
It's not the only way, but it's the easiest way. Rememebr to change the name from bob, to whoever you login as.
now it is working but if I add a log command at the end of my crontab setup, the command does not work anymore.
Do I need to add the log command to the sudoers?

that is working well :
Code:
0 22 * * * bash /usr/bin/rsync_backup.sh

but if I add that at the end, the command does not start :
Rich (BB code):
25 22 * * * bash /usr/bin/rsync_backup.sh >> /var/log/rsync_cron.log 2>&1

I need to add something else here :
Code:
james ALL= NOPASSWD:/usr/bin/rsync
??
thanks
 
It's not the only way, but it's the easiest way. Rememebr to change the name from bob, to whoever you login as.
Code:
CRON[3574]: (james) CMD (bash /usr/bin/rsync_backup.sh >> /var/l
og/rsync_cron.log 2>&1)
Feb 04 07:25:01 ninja CRON[3573]: (CRON) info (No MTA installed, discarding output)
 
It looks like your cron job for running the rsync_backup.sh script is set up, but there's a message indicating that no Mail Transfer Agent (MTA) is installed, so the output is being discarded.

If you want to receive email notifications for your cron jobs, you'll need to install an MTA like postfix or sendmail. Also, you can redirect the output to a log file, which you are already doing with >> /var/log/rsync_cron.log 2>$1

But I would think, depending on how the script is written, the backup would work anyway. It's just saying it can't email
the status/results of the backup out to anyone because it can't find a mail server.
 
It looks like your cron job for running the rsync_backup.sh script is set up, but there's a message indicating that no Mail Transfer Agent (MTA) is installed, so the output is being discarded.

If you want to receive email notifications for your cron jobs, you'll need to install an MTA like postfix or sendmail. Also, you can redirect the output to a log file, which you are already doing with >> /var/log/rsync_cron.log 2>$1

But I would think, depending on how the script is written, the backup would work anyway. It's just saying it can't email
the status/results of the backup out to anyone because it can't find a mail server.
Finaly it did not work like that, cause the user can not write in var.
Code:
/var/log/rsync_cron.log 2>$1
so I chose tmp instead.
thanks
 

Staff online


Top