I wrote a shell script to automatically check the status of Oracle Data Guard and send it via mail.
If I execute the script manually it works like it should.
If I execute the script via a cronjob it just sends empty emails. This behaviour started only after we updated our servers from oracle linux 7 to oracle linux 8.
This is the script:
#!/bin/bash
#. ~/envBIPROD.sh
source /home/oracle/.bash_profile
source /home/oracle/envBIPROD.sh
dgmgrl -silent user/pass >biprod.txt << EOF
show configuration;
show database p1biprod;
show database s1biprod;
EOF
cat biprod.txt | mail -r $(whoami).$(hostname -s)@hostname.tld -s "DATA GUARD Status biprod" [email protected]
This is the "envBIPROD.sh" script which sets the oracle home:
export ORACLE_SID=BIPROD1
export ORAENV_ASK=NO
. oraenv
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
Also the file "biprod.txt" is just empty when the script is run by cron.
envin the script so you can see what your environment is.envBIPROD.shwhich invokes the oraenv utility to set the ORACLE_HOME.idto see what username and groups you are in shell and in cron. Start a new bash with nothingenv - bash, then source those scripts, and see if it still runs.>>/tmp/cronjob.log 2>&1to the command in crontab (and if you have anything like2>/dev/null, remove it -- that's hiding errors, which is the opposite of what you want). Then check the log after it runs and see if you see anything informative.2>&1after the>> /cloudfs/dba/scripts/data_guard_status_mail_BIPROD.logor it won't work.