The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-26-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
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
Reply With Quote
Forum Sponsor
  #2  
Old 10-26-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,612
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)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0