-1

I have no idea what is happening here ?? I have a script which give the status of db down or up .if i run in normal terminal like command prompt its wrking but in crons only print and send mailx msg.please help me i am struggling since long.Somebody advice me to put shebag i put #!/bin/sh but nothing working.

if i schedule in crons liks

* * * * * /home/bin/defesty.sh 

it's only print msg like db down but If execute normal it's showing correct result. Please help me where i am lacking.

#!/bin/sh
cd /sar/chl/db/ladb1
$DLC/bin/proutil ladb1 -C holder > /dev/null
retcode=$? > /home/bin/t.txt

if [[ $retcode -ne 16 ]] ;
then
    echo "Chile ladb1 database  is down in production hours"  >  /home/bin/logs/dboutage1.txt
    mailx -s "Chile db ladb1 down" shaatre@hit.com < /home/bin/logs/dboutage1.txt
fi

cd /sar/chl/db/ladb2
$DLC/bin/proutil ladb2 -C holder > /dev/null
retcode=$?

if [[ $retcode -ne  16 ]] ;
then
    echo "Chile ladb2 database is down in production hours" > /home/bin/logs/dboutage2.txt
    mailx -s "Chile db ladb2 down" shaiae@hit.com < /home/bin/logs/dboutage2.txt

fi
cd /sar/pru/db/ladb1
$DLC/bin/proutil ladb1 -C holder > /dev/null
retcode=$?

if [[ $retcode -ne 16 ]] ;
then
    echo "Peru ladb1 database is down in production hours" > /home/bin/logs/dboutage3.txt
    mailx -s "Peru db labdb1 down" shaiae@hit.com < /home/bin/logs/dboutage3.txt

fi

fi
cd /sar/pru/db/ladb2
$DLC/bin/proutil ladb2 -C holder > /dev/null
retcode=$?

if [[ $retcode -ne 16 ]] ;
then
    echo "Peru ladb2 database is down in production hours" > /home/bin/logs/dboutage4.txt
    mailx -s "Peru db ladb2 down" shaiai@hit.com < /home/bin/logs/dboutage4.txt

fi

Please help me I am strugling

Barmar
  • 741,623
  • 53
  • 500
  • 612
Raj
  • 1
  • 2
  • Where do you set `$DLC`? If you set that in one of your shell startup scripts like `.profile` or `.bashrc`, it won't be set in `cron`. – Barmar Aug 25 '23 at 22:32
  • The question is tagged `bash`, but the script is run with `/bin/sh`. They're not the same thing. – Barmar Aug 25 '23 at 22:33
  • What's the point of the redirection in `retcode=$? > /home/bin/t.txt`? Assigning variables doesn't produce any output. – Barmar Aug 25 '23 at 22:34
  • Please choose a headline that fits the topic. – Cyrus Aug 25 '23 at 22:35
  • In general, if a script doesn't work correctly from cron, it's usually because it depends on settings from your startup scripts. – Barmar Aug 25 '23 at 22:36
  • To get some useful hints paste your script at http://www.shellcheck.net/. – Cyrus Aug 25 '23 at 22:37
  • Sir i just check otput in t.txt so no output – Raj Aug 25 '23 at 22:37
  • Do i need to export DLC also? – Raj Aug 25 '23 at 22:38
  • he question is tagged bash, but the script is run with /bin/sh. They're not the same forget to include this sir .I put from begning #!/bin/sh – Raj Aug 25 '23 at 22:39
  • 1
    Replace `/home/bin/defesty.sh` with `/home/bin/defesty.sh >/tmp/logile 2>&1`. Maybe this logfile contains important informations. – Cyrus Aug 25 '23 at 22:40
  • This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Aug 25 '23 at 22:41
  • See also https://stackoverflow.com/tags/cron/info . Good luck. – shellter Aug 25 '23 at 22:44
  • Replace /home/bin/defesty.sh with /home/bin/defesty.sh >/tmp/logile 2>&1. Maybe this logfile contains important informations. – Cyrus 1 min ago – Raj Aug 25 '23 at 22:45
  • ok sir i am doing right now – Raj Aug 25 '23 at 22:45
  • No I set dlc path in script everything i did not no result. :( – Raj Aug 25 '23 at 22:56
  • But why result is correct if i simply do ./defesty.sh?? – Raj Aug 25 '23 at 22:58
  • but not in cronjobd – Raj Aug 25 '23 at 22:58
  • can anybody help me from this forum? – Raj Aug 25 '23 at 23:00
  • 2
    "My script, which works, won't run from cron" is an extremely frequent Unix scripting question. Please do a little more research about it. It almost always boils down to: (1) the environment (e.g. PATH or other variables). (2) the privileges (wrong account or whatever); (3) directory (script works in a particular directory) (4) interaction: the script needs a TTY. (5) shell: cron runs the command using a different shell from your interactive one. – Kaz Aug 26 '23 at 01:11
  • Also see [CronJob not running](https://stackoverflow.com/q/22743548/4154375). – pjh Aug 26 '23 at 11:18

0 Answers0