You could write a wrapper script to run your job...
Make sure, though, to use full path names in both your cron job script, and the wrapper.
For example, if your script, let's call it fullback.ksh, makes a full backup of your /home filesystem, you could write a script like this (let's call this wrap-full.ksh):
This assumes, of course that your backup script will pass the return code out to it's controlling process; in this case, the wrapper script.
It should be said though, that this should be tested first, since I do not use this type of reporting myself, and I haven't tested this approach.
What happens to the script you have written, if there is no exit code? The script I am calling will provide me exit code only if their is some error and else no exit code is provided. Will the script work if no exit code is obtained (per your script, say, fullback.sh provides exit code only if there is some error)?
What I meant by exit code is the value of $?.
Under normal circumstances, like a successfully run command, the exit code will be 0. If there's an error, it will be something else. The sample script above checks to make sure that $? = 0, and if not, it will send an email.
The concern I have is that something in whatever script is run may run successfully after the failed command... I don't know if I'm explaining very well, so I'll try to show you:
So, you see, unless you told the fullback script to "exit 1" (or exit anything not equal to 0) after any component failed, it might not email you if it does fail.
It depends completely on your script (the fullback.ksh one), is should be easy to make sure it does this correctly...
On the other hand, if you're going to be rewriting to do this, why not put them all together into one? Here's a very simple example:
I guess it all depends on what you're trying to do.
And please let me know if I don't make any sense... I'm kind of tired here
Thanks LivinFree for the details. I understand what you are saying.
I am trying to stop/start a server (i.e, bouncing the server) through a cron job using the stop/start script provided in the server. The script returns exit value only if there is an error. (i.e, if (error) then exit 2). If there are no error, i.e, if the server stop/start without any problem, then there is no exit code. So, when there is an clean start, since exit value is nothing, what will [$? -ne 0 ] return? Will it return true or false?
If the script does "exit 2" when it fails, you will get an email using the same logic as the script above.
If the script completes normally, then it should exit 0 and give you no email.
Hi,
When run the script directly...it executes as expected. But when put it in crontab the job fails with this error:
Connection not open
08003: Connection not open
Unable to connect to the database...
how come it is not able to connect when cron job fires?... Do I need to... (7 Replies)
Hi Guys...
I have a bulk email program that sends out an email to a subscribed mail list.
The list contains around 2000 addresses.
My server is Centos 5 64bit
PHP 5.2
Mysql 5.1
The program is set to send emails in batches of 100.
Cron is set to run every minute
Now for the problem:... (2 Replies)
I added a shell script to cron that executes every 5-15 minutes. It's used to monitor multiple environments, so it has to ssh to each machine to check the status of that machine. Sometimes, I may have more than one instance of this script running at the same time. So, here's my problem. I've... (2 Replies)
Im having a problem with my ftp CRON jobs. I have another related (but not the same question in shell scripting).
My FTP CRON jobs connect to a server and drop some files off, if for some reason it cannot connect to the server (timesout/password wrong etc) instead of stopping, it tries again... (3 Replies)
Hello,
I have added the following entry in my cron file:
* * * * * . /home/texprd/.profile>/dev/null 2>&1; echo "test" >> /home/texprd/test.log 2>&1
The cron fails ie the added command fails to append "test" in the test.log file. However if I run the command manually from the shell... (3 Replies)
I have a very basic script that essentially sends a log file, via FTP, to a backup server. My cron entry to run this every night is:
55 23 * * * /usr/bin/archive_logs
The script runs perfectly when executed manually, and actually worked via cron for about three weeks. However, it mysteriously... (3 Replies)
Hi
Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem.
Im... (15 Replies)
I have two different cron jobs that run on the same days. The jobs are 7 hours apart. Both jobs are set to send notification emails when they start running.
Both jobs always run successfully, but I only receive an email from the first job. I never get the email from the second job.
... (0 Replies)
Getting ready for Sarbanes Oxley and I was told that I need to create a cron.allow file for the box so that only specified users can create cron jobs. That was easy enough, and I put in all the accounts that had scheduled cron jobs such as:
root
lp
My oracle account
A couple of programmer... (1 Reply)