I am using scp for backuping data. When I get the cron output(using crontab file for cron operations) with mail, I do not get any output. The scp operation is done succesfully.
So, in the terminal I get for example: test.file 100% 1489KB 1.2MB/s 00:00
But in the cron output, I do not get the output of the command.
Does someone know how to do this or which other way do you use to get information about the command?
Thanks.
Generally cron is good about sending out any terminal output from it's jobs to the email account for the user on the box it was run under. Sometimes people setup cron jobs with the output specifically redirected or suppressed so that this does not happen. Make sure that this is not the case. If you like you can post your crontab line here and we can tell you.
Also, in order to get the email, you either need to check the mailbox of the user on the box the job runs as, or set it up to route somewhere else. You can usually do this with the system email alias file often in /etc/mail/aliases. For example my boxes all have a line that says "root: [email protected]" so that I receive the emails for all cron jobs run as root.
Edit 1: Apparently scp detects when it is being run from a terminal and changes it's output to silent when it is not. Adding a -v should over-ride this behavior.
Edit 2, alternate solution: I highly recommend using
rsync
instead of scp for this kind of operation. It is designed with this kind of repeated synchronization in mind, handles cases like being able to transfer only updated parts of file or directories etc. It's output is also more suited to use in cron. You can still use ssh for the transport and authentication:rsync -e ssh -v source_file_or_dir user@remotehost:dest_file_or_dir
. Adding-a
for archive mode to synchronize recursive directories and match file properties and--delete
to include deleting remote files not found locally are common options. Be sure to end both the source ad dest arguments with a trailing slash (/) if you are synchronizing directories.