KSH script help needed ( nice error trap routine ?)

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat KSH script help needed ( nice error trap routine ?)
# 1  
Old 02-13-2012
KSH script help needed ( nice error trap routine ?)

I am running a script that runs a loop and executes a command on ${i} until the end of the for loop.

From time to time the command generates an error ( which is good) for example ERROR0005:

How can I trap the error and send an email echoing the ${i} variable in the loop and the error ?

and or better yet run a command that fixes the error based on ${i} + the error code?

This is a RH Enterprise 5.x OS using the K-Shell ( we moved from a Unix to linux environment and have hundreds of scripts to migrate so we kept the ksh format to make life easier)
# 2  
Old 02-13-2012
Do you mean the ERR trap code?

Code:
trap 'commands go here;
       more commands;
       yet more commands; 
       echo |myscript.sh ERROR | mailx -s "error on myscript" me@mycompany.com;  
       exit 1'  ERR

The mailx statement sends email.

EVERY command that returns non-zero gets routed into the trap. Example: when you are using grep to test a string and it fails, you end up in the trap. So, you will have to have a global variable that holds the error text so the trap can ignore most harmless non-zero returns
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 02-13-2012
Thanks for the suggestion but how would that fit into a for loop?

for i in ${list}
do
command
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trap Oracle error in shell script

sqlplus -s usrname/password@dbSID <<-SQL >> logfile @create_table.sql commit; quit; SQL I am running this script to execute an sql file. I want to display the oracle error if anything found during execution of the sql file and exit from script. Please suggest How do it. (1 Reply)
Discussion started by: millan
1 Replies

2. Homework & Coursework Questions

VM trap may work differently than a pure install trap.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: That is the last reply I received from my instructor, and I'm looking for some alternatives. When using... (2 Replies)
Discussion started by: newuser45
2 Replies

3. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

4. Shell Programming and Scripting

Call Nice command (priority) from /bin/ksh

Hello, I am just starting with shell scripting, as everyone will soon see from my question. What I'm trying to do is call the Nice command to set the script process priority from /bin/ksh. The difference is I'm running it not directly through the shell, but through Bigfix (very similar to... (3 Replies)
Discussion started by: solly119
3 Replies

5. Shell Programming and Scripting

using trap in ksh

I have a script that prompts the user for a response. How can I use the trap command to capture the question ask and the users response to a log file? Thanks in advance,:D (1 Reply)
Discussion started by: toor13
1 Replies

6. Shell Programming and Scripting

Error running the script.... Help needed. Please

I have another Question: I tried to run the following script: (I actually wanted to print out the second field in the text field.) #!/usr/bin/ksh set -x readfile=/dir1/data.txt cat $readfile | while read line do x = `echo $line|awk '{print $2}'` echo $x done But, it shows the... (3 Replies)
Discussion started by: ss3944
3 Replies

7. Shell Programming and Scripting

Want to trap script error and return line number of failure

Hey all UNIX nerds- I've built a shell script which runs pretty well- only I want it to have much better error trapping. (Like the kind I could apply to every shell script I write). I'm not a UNIX genius, and could really use a bit of help. The original script goes something like this: 1... (3 Replies)
Discussion started by: stevekerver
3 Replies

8. Shell Programming and Scripting

Apache Subnet consolidation script/routine help needed

I have a rather simple routine that I would like to fine tune. I am having scripters block if that exists. Trying to tally up that amount of subnets after I performed an awk and uniq from zipped apache logs. For instance, on a solaris 10 system: This does work gunzip -c access_log1.200834.gz |... (2 Replies)
Discussion started by: NYG71
2 Replies

9. Shell Programming and Scripting

Cntl+z Trap is not detecting ??? Help required to add a trap detection ???

Hi folks, I have tried to add some trap detection in the below script....this script is used to monitor database activities...in a rather awkward way :rolleyes:.... The idea behind adding trap is that....this script creates lots of temporary files in the running folder to store the count... (1 Reply)
Discussion started by: frozensmilz
1 Replies

10. Programming

nice command and nice() system call

Hi I want to implement the nice command in the shell that I am building. I came to know that there is a corresponding nice() system call for the same. But since I will be forking different processes to run different commands typed on the command prompt, is there any way I can make a command... (2 Replies)
Discussion started by: tejbuch
2 Replies
Login or Register to Ask a Question