Need exception handle for this script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need exception handle for this script
# 1  
Old 12-11-2014
Need exception handle for this script

Hi

This is script to move log files from one location to other which is working fine. I need to add exception handling in this new to scripting. Please help
Code:
#!/bin/ksh
DB=QACCABOP
dumppath='/udb/udbpa032/dump_data/offshore/Tran_logs'
msg='/udb/udbpa032/utilities/DBAscripts/msg/msg.out'

logpath1=`db2 get db cfg for $DB | grep -i 'Path to log files' | grep -v Changed | awk ' { print $6 } ' `

ACTIVELOG=`db2 get db cfg for $DB | grep -i 'First active log file' | awk ' { print " ls -ltr | grep " $6 } ' | sh - | awk ' { print  $9 } '`

cd $logpath1
logfilper=`df -gt . | grep log | awk ' { print $5 } ' | rev | cut -c 2- | rev`

if [ $logfilper -ge 50 ];then
   echo "-------------Moving old logs to dump ----------" `date +%Y-%m-%d-%H.%M.%S`  >> $msg
   #FIRSTLOG=`ls -ltr *.LOG | head -n 1 | awk ' { print $9 } '`
   #echo "Oldest log in the directory $FIRSTLOG"
   find . -newer SQLLPATH.TAG \! -newer $ACTIVELOG | grep -v $ACTIVELOG | awk ' { print "mv" " " $0 " "  \
   "/udb/udbpa032/dump_data/offshore/Tran_logs" } ' | sh -
   cd $dumppath
   ls -ltr *.LOG | awk ' { print "gzip " " " $9 } ' | sh -
   find . -name "*.LOG" -mtime +7 | awk ' { print "rm " $0 } ' | sh -
else
   echo "--------------- FS is below threshold --------"  `date +%Y-%m-%d-%H.%M.%S`  >> $msg
   exit 0 
fi


Moderator's Comments:
Mod Comment Please use code tags for your code and data, thanks

Last edited by vbe; 12-11-2014 at 12:56 PM.. Reason: indent...
# 2  
Old 12-11-2014
Welcome to the forums, what do you call exceptions handling?
What have you tried and where are you stuck?
# 3  
Old 12-11-2014
hi vbe,

This script is running fine for particular DB. If it fails i some of the command how will i shld get alert. I treid for return code 0, but if for example
Code:
ls -ltr *.LOG | awk ' { print "gzip " " " $9 } ' | sh -

it return code 0 even if it gets cannot find the *.LOG tht is correct as command ran file.

Incase it fails want to know how to capture it.

May be the approach what i used is wrong.

Redgs
Paul

Last edited by vbe; 12-11-2014 at 12:53 PM.. Reason: code tags , and plain english please...
# 4  
Old 12-11-2014
What exactly are you trying to achieve with ls -ltr *.LOG | awk ' { print "gzip " " " $9 } ' | sh - and what be the difference to gzip *.log? This would also supply an exit code in $? if sth went wrong.
# 5  
Old 12-11-2014
Code:
liux001(db2inst1):QACC:/udb/db2inst1/dump_data/offshore/Tran_logs>int "gzip " " " $9 } ' | sh -                      <
ls: 0653-341 The file *.LOG does not exist.
liux001(db2inst1):QACC:/udb/db2inst1/dump_data/offshore/Tran_logs>$?
ksh: 0:  not found.

As it still cldn't find the logs the statement failed, so still the return code give 0. As ls -ltr command went properly

May be i m wrong. Please check the return code its giving



Moderator's Comments:
Mod Comment
Please use CODE tags for code, files, input & output/errors
It makes it much easier to read and preserves multiple spaces to aid formatting and fixed width needs.

Last edited by rbatte1; 12-11-2014 at 01:21 PM.. Reason: Added CODE tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

2. Shell Programming and Scripting

Shell script to unmonitor the mounts in exception file

I am trying to write a shell script for monitoring the file system mount. command I am using will retrieve a output as shown below. /dev/fsv29 2% /apps/rj/pgl/bslSys I also need to add exception mounts in a file and I would like script to ignore the mount which I specify. If I add the... (6 Replies)
Discussion started by: chandu123
6 Replies

3. Shell Programming and Scripting

Handle occasional condition in expect script

Hi, I am using Solaris OS, I want to handle an occasional expression in expect script while logging into a remote server with ssh. In normal scenario the expected expression is as below, spawn ssh $user@$ip expect "assword:" send "$password\r" but in a condition when the remote server... (2 Replies)
Discussion started by: varunksharma87
2 Replies

4. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

5. Shell Programming and Scripting

how to handle , in data where separator also commas in awk script

TEST_HEME,"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1",CELL when I split by FS="," then $0=TEST_HEME $1="SubNetwork=ONRM_RootMoR $2=SubNetwork=ARNC1" but I need this will be single value "SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1" (4 Replies)
Discussion started by: Hemendra
4 Replies

6. Shell Programming and Scripting

help to handle the expect script issue

Hi experts I know the expect script can match the terminal output to run the the following cmd I write a script with expect named "test", I want to run ten "test" with background running, for ((i=1;i<=10;i++) do ./test -n $i done I find all the output of test will print on one... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

7. Shell Programming and Scripting

i'm new to shell can handle this script for me plz

Write a shell script named displayargs that prints FOUR lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters there were, the third line tells what the last parameter was, and the fourth line tells what the first parameter was. For... (8 Replies)
Discussion started by: kedah160
8 Replies

8. Shell Programming and Scripting

Database handle to a child script using exec

Hello, Can I pass a database handle created in parent script to a child script triggered using exec ?? Parent script ========= $dbh =DBI->connect{......); # Db handle creation $param1 =10; # parameter one exec "childscript.pl $param1 $dbh "; # executing childscript.pl with two parameters... (0 Replies)
Discussion started by: coolbhai
0 Replies

9. Shell Programming and Scripting

Shell Script to Handle Quarterly Backup.

Hi I'm not to shell script and I'm trying to write a simple shell code to do the following. Shell script should be run in March, June, Sept, & Dec respectively to back up files last modified in the 1st, 2nd, 3rd, and 4th quarters. I've have the following code. #!/bin/csh set v1 = `date... (1 Reply)
Discussion started by: Magshabib@gmail
1 Replies

10. Shell Programming and Scripting

How to handle errors during script execution

Hi I have written a script which returns a number. This resulting number I assign to the variable for example: $ A=`get_dbnum 118 ttrn` $ echo ${A} 8208 $ The script becomes interective once the error occures and the number is not found. It prompts the user to enter the number. The... (1 Reply)
Discussion started by: aoussenko
1 Replies
Login or Register to Ask a Question