- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Error Codes in shell script.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:22 PM
06-23-2004 10:22 PM
Error Codes in shell script.
I wanted to know how can i trap the exact
error code and error message within the shell script for "mv " command to know what caused the actual problem ..ie was it file permission erro or no space on target or something else.
Are there any specific codes reflected and how can i trap them.
regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:32 PM
06-23-2004 10:32 PM
Re: Error Codes in shell script.
returns a code which tells the shell to print an error message.
The default exit (no arguments) will exit the shell program with the status of
the last command executed. You can exit with a diferent exit status; see the
man pages for the exit statuses of each command. The usual exit
statuses are:
0 Success.
1 A built-in command failure.
2 A syntax error has occurred.
3 Signal received that is not trapped
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:33 PM
06-23-2004 10:33 PM
Re: Error Codes in shell script.
You can do a set +x in the beginning of the script to see the script execution.
The error message coming out of mv will be sent to stderr so you can redirect the output to a file 2>file and see the error message.
apart from that I cannot think of anything now.
manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:34 PM
06-23-2004 10:34 PM
Re: Error Codes in shell script.
You can try to capture the standard o/p and err to a file .
mv file1 file2 >mv.log 2>&1
The log file should contain the errors message .
Regards
BL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:36 PM
06-23-2004 10:36 PM
Re: Error Codes in shell script.
like 0,1,2 but i believe their are some specifice error codes addressing some specific error messages viz. permission error
,space error etc.
How can i trap this erros in my shell scripts
to reflect the actual error.
regrds,
Sunil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:44 PM
06-23-2004 10:44 PM
Re: Error Codes in shell script.
Don't know your script but,
echo $?
This will display the error code generated by the earlier command.
Maybe this will help you.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:46 PM
06-23-2004 10:46 PM
Re: Error Codes in shell script.
The specific error which you can generate in a C program (syscall failure) like permission denied cannot be trapped in a shell script if the application (mv) is not givint it to the script.
manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2004 01:09 AM
06-24-2004 01:09 AM
Re: Error Codes in shell script.
The only way this can be done is to trap the actual numeric value (0, 1, 2, etc) via the $? variable. I do this as follows:
mv
rval=$?
Then I can test the value of rval (because $? is constantly changing).
Now, as to getting the actual error, you need to learn what the various return codes are (either via man pages or experimentation). To display a meaningful text message, you can do something like this:
case ${rval}
in
0) MESSAGE="Move successful";;
1) MESSAGE="Out of disk space";;
2) MESSAGE="File not found";;
*) MESSAGE="Unknown error - return code is ${rval}";;
esac
I've made up the messages for 1 and 2 (just to provide an example).
Over time, as you get "Unknown error - return code is ___" you just add on to the script and build up the case statement.