Page 1 of 1

Script not working.

Posted: 2019/07/17 13:38:40
by gdolidze
I have 2 server, one is DB server and the other is APPL.

We shutdown the application when we backup the DB, i made a script that checks the db server from the APPL server and starts the application.
This script works when i execute manual but when it executes from the crontab the IF statements always comes as true.

Code: Select all

#!/bin/bash
var="no"
echo "$(date)" | mail -s "Oracle is down for backup." linuxadmin@cjh.org
while [[ "$var" != "yes" ]]
do
#echo "$(date)" | mail -s "Oracle is down for backup." linuxadmin@cjh.org
if ssh root@dbserver -p 22 ps aux | grep -v 'grep' | grep -q 'pmon';then
    {
        echo 'Found'
        var="yes"
        sleep 1m
        echo "$(date)" | mail -s "Oracle has started and now starting Rosetta." linuxadmin@cjh.org
        /exlibris/dps/d4_1/profile/dps_startup_all
    }
else
    {
        echo 'Not Found'
    }
fi
date
sleep 5m
done

Re: Script not working.

Posted: 2019/07/17 14:18:18
by lightman47
What about
if [ ssh root@dbserver -p 22 ps aux | grep -v 'grep' | grep -q 'pmon' ];then

Re: Script not working.

Posted: 2019/07/17 14:28:46
by TrevorH
What about using pidof pmon instead of that horrid ps fax | grep -v grep | grep -q pmon.

Re: Script not working.

Posted: 2019/07/18 13:25:37
by gdolidze
when i execute this script on the cli it works but when it runs from crontab is always does The true side of the if statement,
so if oracle is down it does this, its suppose to say not found. Again this works when executed manually but it has issue from crontab.

{
echo 'Found'
var="yes"
sleep 1m
echo "$(date)" | mail -s "Oracle has started and now starting Rosetta." linuxadmin@cjh.org
#/exlibris/dps/d4_1/profile/dps_startup_all
}

I dont know if the issue is the script or crontab.

I am going to try pidof and get back to you.

Re: Script not working.

Posted: 2019/07/18 14:16:31
by TrevorH
When it's run from crontab you run echo, mail, ssh and grep prior to that test. None of those are fully qualified so will depend on being found in $PATH. I tested by running "/bin/env > /tmp/rootenv.txt 2>&1" from crontab and PATH is set to PATH=/usr/bin:/bin and all of those ought to be found but it's good practice to specify the full path to the thing you are running in crontab jobs.

What is the output from aureport -a and are there any entries that are timestamped the same time as the last time you tried to run this from cron?