Home » Infrastructure » Unix » Need small modification in shell script
Need small modification in shell script [message #643853] Tue, 20 October 2015 05:38 Go to next message
praveenk768
Messages: 5
Registered: October 2015
Junior Member
Hi All,
I am new to shell script.
In the below script, I am calling one sql file(test.sql). If this file returns any data then I have to generate this file(test_$RUN_DATE.FCNA). If the sql files returns no data then I dont want to generate this file(test_$RUN_DATE.FCNA).
I tried one approach like: check the size of FCNA files and based on this I am deleting the FCNA file. But, client are not okay with deletion of file.
Is there any to handle this requirement?

#!/bin/bash
# Case 9523 SQL to run daily at 7pm
# spool file is placed in otmtms/staging then the normal ftp script will copy
# it to otmtms/out for pickup and otmtms/acrhive
# Version 1.0 12-28-2012
SQL_FILE=/ftp/otmtms/config/test.sql
#SID=OTM60APL2D
SID=OAPL2P
RUN_DATE=$(date +%Y%m%d%H%M%S)
tempfile=/tmp/.exec_$RUN_DATE
# Set ORACLE_HOME and related variables
ORACLE_HOME=/u01/app/oracle/product/11.2.0; export ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
NLS_LANG=American_America.UTF8; export NLS_LANG
# Set PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
sqlplus -S /nolog <<EOF
spool /ftp/test_$RUN_DATE.FCNA
whenever sqlerror exit FAILURE
connect SHIPMAXOWNER/shipmaxowner@$SID 
@$SQL_FILE
EOF
#fcna= /ftp/test_$RUN_DATE.FCNA
#if [ -s $fcna ]
#then
# echo "Exception Encountered****Notification sent via maill****".
#else
# rm /ftp/test_$RUN_DATE.FCNA
# echo "deletion success****".
#fi
Re: Need small modification in shell script [message #643862 is a reply to message #643853] Tue, 20 October 2015 07:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I see you use the script I gave to you in your previous topic.
A little thank would be welcome.

Re: Need small modification in shell script [message #643866 is a reply to message #643862] Tue, 20 October 2015 07:42 Go to previous messageGo to next message
praveenk768
Messages: 5
Registered: October 2015
Junior Member
Thanks for your help michel. Can you please help with this
Re: Need small modification in shell script [message #643868 is a reply to message #643866] Tue, 20 October 2015 07:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Why not remove it if it is empty?
Or you can create another file (in /tmp) and move it into this one if it is not empty.

Re: Need small modification in shell script [message #643876 is a reply to message #643868] Tue, 20 October 2015 09:04 Go to previous message
praveenk768
Messages: 5
Registered: October 2015
Junior Member
Thanks Michel
Previous Topic: Sometimes getting SP2-0734 error message
Next Topic: How to test the firewall rules on SunOS
Goto Forum:
  


Current Time: Thu Mar 28 07:17:09 CDT 2024