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.
Your script is probably running in a directory where it doesn't have permission to create or write to a file and so
>biprod.txt
is failing to create the file or to overwrite an existing file.If
biprod.txt
is intended to only exist while your script is running then do this instead:though you almost certainly could be using
< "$biprod" mail ...
instead ofcat "$biprod" | mail ...
). It wouldn't hurt for you to add someprintf
s to report failures either.