log file when the script fails !


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting log file when the script fails !
# 1  
Old 01-06-2009
log file when the script fails !

i have a script that will retrive some info from database. The script is working fine but i have to add new feature in it when the script fails or retrive null result it should reflect in the log file.

below the script AMR_Inactive.sh
Code:
while read i
do

connect1=`sqlplus -silent amit/qwerty@edna.world <<END
set pagesize 0 feedback off verify off heading off echo off
SELECT meter.X_UDC_ASSET_ID
 FROM
    SIEBEL.S_ASSET Meter,
    SIEBEL.S_ASSET SDP,
    SIEBEL.s_asset_rel ARSM,
        SIEBEL.S_ADDR_PER Premise,
        SIEBEL.S_ASSET Route,
        SIEBEL.s_asset_rel ARSR
 WHERE
        ARSM.par_asset_id = SDP.row_id AND
        ARSM.asset_id = Meter.row_id AND
        ARSM.relation_type_cd = 'SDP-METER' AND
        ARSM.x_rel_status = 'Active' AND
     SDP.PER_ADDR_ID = Premise.row_id AND
        ARSR.par_asset_id = Route.row_id AND
        ARSR.asset_id = SDP.row_id AND
        ARSR.relation_type_cd = 'ROUTE-SDP' AND
        ARSR.x_rel_status = 'Active' AND
                Premise.X_CLIENT_PRMSE_ID = '$i';
exit;
END`
echo "Completed for $i" 
echo "$connect1" 
done < TNS_AMRI_INACTIVE.txt

contents of TNS_AMRI_INACTIVE.txt
Quote:
0002034694
if suppose for this data the script returns null result i should get the info "No rows returned" in my log file.i m runnig the script using crontab

AMR_Inactive.sh > AMR_Inactive.log 2>&1

Last edited by ali560045; 01-06-2009 at 02:26 AM..
# 2  
Old 01-06-2009
The only thing you have to do is check the ${connect1} value before printing it:
Code:
if [ -n "${connect1}" ]; then
    echo "${connect1}"
else
    echo "No rows returned"
fi

instead of just:

Code:
echo "${connect1}"

# 3  
Old 01-06-2009
Thanks . But what if suppose after select statement i m updating using that value and if update fails how to get that in log file.

Basically how to show in the log file that the given SQL query has really worked successfully or not .......

Last edited by ali560045; 01-06-2009 at 03:42 AM..
# 4  
Old 01-06-2009
i have now modified the code instead of select i m now doing update . i have use the spool concept here.

But still i m not getting any info like "0 rows Updated" in the spool file. How to get that info in spool file

below the code using update
Code:
#!/bin/ksh

. $HOME/conf/systemProperties/EnvSetup.properties


sqlplus -silent amit/qwerty@edna.world <<END
set pagesize 0 feedback off verify off heading off

spool Script_Fails.log 

UPDATE SIEBEL.S_ASSET_XM SDPX 
SET SDPX.ATTRIB_03   = 'Inactive', 
SDPX.LAST_UPD_BY = '1-42V', 
SDPX.LAST_UPD    = SYSDATE, 
SDPX.ATTRIB_04   = 'SQQ3' 
 WHERE SDPX.PAR_ROW_ID  IN ('090845086LG')
   AND SDPX.ATTRIB_01   = 'AMR Ready' 
   AND SDPX.ATTRIB_03   = 'Active';

commit;
exit;
END

when RUN this update statement in my database it is showing "no rows Update". This same information i want in the spool file.How to get that ?

Thanks in advance

Last edited by ali560045; 01-06-2009 at 03:59 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Except script fails to check file exists or not in remote node

Dear members, The following expect script connects to remote node and check for the file "authorized_keys" in directory /root/.ssh in remote node. However the result is always found even if the file exist or doesn't exist. expect { "$fname" { send_user "found\n" } Any idea what is... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

2. Shell Programming and Scripting

Bash script fails when run as file

The following bash script fails with error message: "./phpquery_KNBB_html_reader.sh: line 65: syntax error near unexpected token `done'" when do ./<scriptname> in the shell. However when I copy-paste the entire contents of the file directly into a shell environment it runs ok returning the intended... (2 Replies)
Discussion started by: BurritoSolution
2 Replies

3. Shell Programming and Scripting

Setuid not working in Linux as script fails to write to file.

Hi, I have the following 3 test files to test setuid bit which if it works I would like to implement in our application. However setuid doesnot seem to be having any impact on my test below.Following are the 3 files of interest in /tmp/ folder. $ ls -ltr *env* -rw------- 1 g332008 users 6... (23 Replies)
Discussion started by: waavman
23 Replies

4. Shell Programming and Scripting

File check script fails for multiple files

I want to check if any file with testing*.txt exists but my script fails if more than 1 file exists. It works fine for a single file if then echo "TEST21" fi -------------- bash: How do I fix this? Thanks Please use code tags next time for your code and data. (8 Replies)
Discussion started by: sumang24
8 Replies

5. Shell Programming and Scripting

SFTP Script fails to transmit the file

I have written a Unix Script to automate the process of File transfer from Our server to vendor Server but the automation Script fail when Progress meter is around 65-70% Complete. Why is this haapening? See the Log File Contenet: spawn sftp -o IdentityFile=/home/lawsched/ah_rsa XXX@YYY.com... (10 Replies)
Discussion started by: Mahesh Gajapath
10 Replies

6. Shell Programming and Scripting

Execute shell script even if the first script fails

All, I executing a perl script and shell script from a master shell script. i will execute the perl script first and have to execute the shell script after the completion of perl execution. Below is the code i use for it, script_root='/dev/scripts' /usr/bin/perl -S $script_root/test.pl;... (5 Replies)
Discussion started by: vel4ever
5 Replies

7. Solaris

Script fails when generated output file reaches a particular size

Hi All, New to unix. Here is the problem. Running a script that extracts data from hyperion essbase and generates a file in unix. This script fails most of the times with a very low success rate. The data has increased a lot in the last few months resulting in the file being more than 2 gb. ... (2 Replies)
Discussion started by: noufalshaw
2 Replies

8. UNIX for Advanced & Expert Users

when a process fails to write to /dev/log

Hi , when a process fails to write to /dev/log ? (1 Reply)
Discussion started by: Gopi Krishna P
1 Replies

9. UNIX for Advanced & Expert Users

why script fails sometime?

Hi, I am trying to run a shell script on solaris,some time it works fine and some times it fails unexpectedly. There is a script called "autostart.sh" which automatically starts the Application server but some times the script fails to strat the application server. can anyone tell me what... (10 Replies)
Discussion started by: tahir23
10 Replies

10. Shell Programming and Scripting

Script fails

Hi, I am trying to install a package on solaris and one of the packaging scripts fail unexpectedly. There is a script called "checkinstall" which checks for the /opt space and aborts the installation if /opt is less than 100MB. In my case, even if /opt has enoguh space, the script fails. ... (8 Replies)
Discussion started by: JStone
8 Replies
Login or Register to Ask a Question