![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| /var/adm/messages error | sunsri01 | SUN Solaris | 2 | 11-09-2007 08:33 AM |
| ftp error messages! | dineshr85 | Shell Programming and Scripting | 1 | 10-18-2007 10:03 PM |
| error messages | murad.jaber | SUN Solaris | 0 | 10-10-2007 11:02 PM |
| error messages in /var/adm/messages | nitinp82 | UNIX for Advanced & Expert Users | 1 | 04-17-2007 07:17 AM |
| error in /var/adm/messages | julie | UNIX for Dummies Questions & Answers | 2 | 08-08-2001 01:10 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Error Messages
I have got script like this
#!/bin/ksh -e function errtrap { es=$? print "ERROR line $1: Command exited with status $es." } trap 'errtrap $LINENO' ERR cp no_perm yes_perm echo "error" When I run the script I get a output like this. ********************** cp: cannot access no_perm ERROR line 7: Command exited with status 2. *********************** I would like to catch the error message " cp: cannot access no_perm " and display that with the print statement rather send in a mail at that place . Is there any variable like $? which catches a error message . Much like sqlerrm variable in oracle . I have done man ksh and did not find any . I am doing this in script so that I don't have a option like cp no_perm yes_perm 2>file and then grep the content of file . Again for some reason i can't do call a script like test.ksh 2>/dev/null Thanks Ashok |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
A little bit cryptic ...
error=$(exec 4>&1 5>&2 ; command goes here 2>&4 1>&5) This swaps the function of stdout and stderr while command is running. So with: error=$(exec 4>&1 5>&2 ; ls -l somefile not-there 2>&4 1>&5) the ls -l for somefile is displayed and the error message regarding not-there is stored in the variable. In your case, a simple cp command that does not write to stdout, you could more simply do: error=$(cp this that 2>&1) |
||||
| Google The UNIX and Linux Forums |