Want to trap the error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to trap the error
# 1  
Old 09-06-2013
Want to trap the error

I was running a script to upload data from file to database but it is failing in middle.Can i use trap command to find the error that is occured while running the script.

Thanks in advance,
Satish.
# 2  
Old 09-06-2013
Provide us some details...
What is your os? (i.e. windows, unix, etc.)
What is your datanase? (i.e. oracle, db2, mysql, etc.)
What kind of script are you having the problem with? ( bash, ksh, perl, etc.)

Post the script and any messages you are receiving and point out which line you think the error occurs on.
# 3  
Old 09-07-2013
Want to trap the error

OS - UNIX
DB - oracle
script - ksh
Code:
handleInterrupts 1 2 3  4 5 6 7 8 9 10 11 12 13 14 15

handleInterrupts
{
     echo "\n handling "
     cp ~$HOME/sat/* ~$HOME/sat/middlefile/*
}

I am trying to print the logs which are getting generating while running the script into other directories

I was able to handle ctrl+c and other interrupts and the files are getting copied successfully.
But if the program is failing at reporting code which is called from the script then the above handleInterrupts function is unable to handle hence the logs are not copied to the destination path.I could not find the reason for my reporting code failure because the files are getting deleted when the whole process is completed.

Is there any other handle interrupt which i can use to copy the logs even if the program ends like the above scenario.

Thanks ,
Satish.

Last edited by Scott; 09-07-2013 at 10:32 PM.. Reason: Added code tags
# 4  
Old 09-07-2013
Quote:
Originally Posted by satishmallidi
But if the program is failing at reporting code which is called from the script
What is this 'program' you are calling from the script?(i.e. sqlplus, another script, etc.)
Where does the 'program' being called log any errors/exceptions that occurs?
Check the exit status code from the 'program' in the script right after you call it:
Code:
if [[ $? = 1 ]] then
  print "$? - ERROR"
fi

# 5  
Old 09-07-2013
Quote:
Originally Posted by spacebar
What is this 'program' you are calling from the script?(i.e. sqlplus, another script, etc.)
Where does the 'program' being called log any errors/exceptions that occurs?
Check the exit status code from the 'program' in the script right after you call it:
Code:
if [[ $? = 1 ]] then
  print "$? - ERROR"
fi

There are at least three problems with these three lines of code. First: You need a semicolon or a newline before the then in your if statement. Second: What happens if the 'program' exits with a non-zero exit status other than 1. (The answer is that this code will silently ignore it.) Third: The $? in the print statement will not be the exit status of the 'program'; it will be the exit status of the conditional expression ([[ $? = 1 ]] which will be 0 if you get to the print statement. I assume that what you intended was something like:
Code:
ec=$?
if [ $ec -ne 0 ]
then    print "$ec - ERROR"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris 10 boot problem - ERROR: Last Trap: Fast Data Access MMU Miss

Hello, We have a T5140 server with Solaris 10 and its suddenly throwing "segmentation core" when I login into the server and not showing any output for commands like df, mount etc. so I had to reboot the server to fix this issue. Please note that there's no boot disk mirroring. But... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. Shell Programming and Scripting

Bash - trap error file not found

Hello. In bash, is there a way to trap error "file not found" when a script call another script which is not found; then abort. Example ( part of script running with -x option set) : + return 0 + RETURN_CODE=0 + ] + /root/bin/200_yast_install/00_reset_yast_install bash:... (5 Replies)
Discussion started by: jcdole
5 Replies

3. UNIX for Advanced & Expert Users

Help - Infinite Loop: Error in trap function

Hi, I was working on implementing error handling in my bash scripts, and decided to use trap to send myself an email incase of any errors. But it seems that somethings has gone wrong, and I am continuously getting same emails for an old error repeatedly (even though I have stopped/killed all... (1 Reply)
Discussion started by: cool.aquarian
1 Replies

4. 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

5. 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

6. Red Hat

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 ? ... (2 Replies)
Discussion started by: pcpinkerton
2 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

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

9. Solaris

"Trap 3e" OBP error on Ultra 5.

My Ultra 5 (Solaris 10) is now unbootable, with the OBP failing with error "trap 3e" When it tries to boot from disk. Disk is a Maxtor 80GB IDE, and was working previously. I've booted to cdrom and run "Format" from Single user, but when I try to read the disk, it just core dumps. I have... (2 Replies)
Discussion started by: akbar
2 Replies

10. Shell Programming and Scripting

Building a better mouse trap, or How many lines of code does it take to trap a mouse?

Hello all, I'm hoping to get a little insight from some of the wily veterans amongst you. I've written a script to check for new outgoing files to our vendors located on our ssl server. It seems to be working ok, but the final question here, will be one of logic, and/or a better way to... (4 Replies)
Discussion started by: mph
4 Replies
Login or Register to Ask a Question