Script not working.

General support questions
Post Reply
gdolidze
Posts: 4
Joined: 2015/06/29 16:14:56

Script not working.

Post by gdolidze » 2019/07/17 13:38:40

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

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Script not working.

Post by lightman47 » 2019/07/17 14:18:18

What about
if [ ssh root@dbserver -p 22 ps aux | grep -v 'grep' | grep -q 'pmon' ];then

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Script not working.

Post by TrevorH » 2019/07/17 14:28:46

What about using pidof pmon instead of that horrid ps fax | grep -v grep | grep -q pmon.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

gdolidze
Posts: 4
Joined: 2015/06/29 16:14:56

Re: Script not working.

Post by gdolidze » 2019/07/18 13:25:37

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.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Script not working.

Post by TrevorH » 2019/07/18 14:16:31

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?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply