I have created a script. Which i have configured in cron to make it run in every 2 min. But script is not running. If I checl the cron log at /var/cron/log .it shows its running in every 2 min. Below is the command which i configured in crontab.
But I am not able to find the way so that this script can run in every two mins.
I don't think your crontab entry is the problem. You need to be sure that ALL the environment variables that make the script run from the command line exist in cron.
Example: you might need to source /etc/profile inside your script
. /etc/profile
You could also modify your cron entry to get errors into a log file
Please post precisely what Operating System and Shell on this and every subsequent thread. Please also post the output from set when you are running in a normal terminal session so we can work out what /bin/sh means when you are running from cron:
uname -a # Blotting anything confidential like machine names with Xs
echo $SHELL
set
There are many areas of your script which need attention:
1) Corona688 has already pointed out that the backticks are neither required nor advisible in this context.
2) The Environment Variable $ESAHOMEINSTALL is not set anywhere in the script. Please post the output from the set command when logged in interactively so we can see your interactive environment (which will be quite radically different from the environment when running from cron).
3) The script includes dodgy numeric comparisons:
if [ "${MSAlive}" -eq 0 ]; then
if [ "${TSAlive}" -eq 0 ]; then
if [ "${TSCheck}" -eq 1 ]; then
In all of these cases, lose the double quotes. You are comparing numbers not strings.
4) Is it safe to assume that the weird output in /tmp/sigcheck.log did not come from the script as posted but only happens if you include . /etc/profile in the script? Executing . /etc/profile in this context is inadvisible because there is no terminal context.
If true, please post the actual output seen in /tmp/sigcheck.log which matces the script posted.
5) The whole script design depends on processing ps -ef every two-minutes. This is madness. Eventually you will hit a moment when the kernel is busy and ps -ef returns a null or incomplete response.
Ideally you would record the PID of the process in a file when it starts. Then you only need to query the one PID. ps -fp<pid> .
At a minimum consider confining to ps -fu<username> where username is the name of the user who owns the crontab.
Within your script, consider code to only react to say three consecutive failures rather than just the one.
Please post precisely what Operating System and Shell on this and every subsequent thread. Please also post the output from set when you are running in a normal terminal session so we can work out what #!/bin/sh means when you are running from cron:
uname -a # Blotting anything confidential like machine names with Xs
echo $SHELL
set
There are many areas of your script which need attention:
1) Corona688 has already pointed out that the backticks are neither required nor advisible in this context.
2) The Environment Variable $ESAHOMEINSTALL is not set anywhere in the script. Please post the output from the set command when logged in interactively so we can see your interactive environment (which will be quite radically different from the environment when running from cron).
3) The script includes dodgy numeric comparisons:
if [ "${MSAlive}" -eq 0 ]; then
if [ "${TSAlive}" -eq 0 ]; then
if [ "${TSCheck}" -eq 1 ]; then
In all of these cases, lose the double quotes. You are comparing numbers not strings.
4) Is it safe to assume that the weird output in /tmp/sigcheck.log did not come from the script as posted but only happens if you include . /etc/profile in the script? Executing . /etc/profile in this context is inadvisible because there is no terminal context.
If true, please post the actual output seen in /tmp/sigcheck.log which matces the script posted.
5) The whole script design depends on processing ps -ef every two-minutes. This is madness. Eventually you will hit a moment when the kernel is busy and
ps -ef returns a null or incomplete response.
Ideally you would record the PID of the process in a file when it starts. Then you only need to query the one PID. ps -fp<pid>
.
At a minimum consider confining to ps -fu<username> where username is the name of the user who owns the crontab.
Within your script, consider code to only react to say three consecutive failures rather than just the one.