Reputation: 123
I am new on writing Unix shell scripts. I have written a script which include Oracle Database sql codes. As you see below, it writes outout of sql codes on text files and i want to send these outputs by mail. It works very well when i run it manually. But when on crontab it does not do it as i want. Sql codes work very well, text files are updated, it sends mail but values are blank in mail. I read some other problems, i wrote all paths but i could not find the problem. I hope you can find the solution. Thank you, best regards
#!/usr/bin/ksh
./home/partner/.profile
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9
ORACLE_BASE=/oracle
ORACLE_SID=----------------
ORACLE_HOME=-------------
USER=------------
PASSWD=--------------
SCRIPTPATH=/home/path-to/scripts/
spoolfile=$SCRIPTPATH/textfile1.txt
spoolfile2=$SCRIPTPATH/textfile2.txt
export NLS_LANG ORACLE_BASE ORACLE_SID ORACLE_HOME
$ORACLE_HOME/bin/sqlplus $USER/$PASSWD<<EOF
@$SCRIPTPATH/code1.sql $spoolfile
exit;
EOF
$ORACLE_HOME/bin/sqlplus $USER/$PASSWD<<EOF
@$SCRIPTPATH/code2.sql $spoolfile2
exit;
EOF
value1=`/usr/bin/cat textfile1.txt`
value2=`/usr/bin/cat textfile2.txt`
if [[ -s $spoolfile ]] ; then
echo "mail1 "$value1 "text "$value2 | mailx -s "subject" [email protected]
else
echo "mail2" | mailx -s "subject" [email protected]
fi
Upvotes: 0
Views: 487
Reputation: 70538
You have
spoolfile=$SCRIPTPATH/textfile1.txt
spoolfile2=$SCRIPTPATH/textfile2.txt
and then later
value1=`/usr/bin/cat textfile1.txt`
value2=`/usr/bin/cat textfile2.txt`
looks like the textfiles are saved in one place and read from another.
Upvotes: 3