The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11:33 AM
ftp error messages! dineshr85 Shell Programming and Scripting 1 10-19-2007 01:03 AM
error messages murad.jaber SUN Solaris 0 10-11-2007 02:02 AM
error messages in /var/adm/messages nitinp82 UNIX for Advanced & Expert Users 1 04-17-2007 10:17 AM
error in /var/adm/messages julie UNIX for Dummies Questions & Answers 2 08-08-2001 04:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-26-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
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
  #2 (permalink)  
Old 10-26-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
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)
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0