How to end script in a cron job?

I've created a script to copy backup files from an HP-UX 11iv3 system to an NFS share on another machine. I want to schedule the script to run via cron. The script is simply three lines of cp /backups/Backup /shared/Backup . I've saved the script as a .sh file and call it with KSH. Do I need to include an end or exit command at the end of the script to ensure it exits cleanly?
Thanks,
Joe

It will exit by itself once done, but you probably want an 'exit 0' at the end in case any of the cp commands couldn't copy.

Cron also has a useful feature where any output from the command gets emailed to you. Generally you want no output for successful commands, but if the command fails, you want cron to tell you about that. So:

#!/bin/ksh

# Redirect error messages so cron can send them to you
exec 2>&1 

cp source1 dest1
cp source2 dest2
cp source3 dest3

exit 0
1 Like

Thank you for the great tips. I've added your suggestions to my script and I'll check on it tomorrow.
Joe

IMHO cron merges stdout and stderr by default.
So there is no need for exec 2>&1 .

2 Likes