- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting problem: grouping and pipes
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
07-03-2002 06:51 AM
07-03-2002 06:51 AM
Scripting problem: grouping and pipes
I have a number of scripts with grouped commands piping their output to mailx. Some of these commands are error trapped, and should exit the program. They aren't.
Try runnng the attached program, and then try it again after removing the " | cat -".
I hope someone can help me!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 07:18 AM
07-03-2002 07:18 AM
Re: Scripting problem: grouping and pipes
To adjust the script to not require the "cat -", then put the "false || errorfunc" within parenthesis. The man for ksh states that "||" has a higher precedence over ";"
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 07:24 AM
07-03-2002 07:24 AM
Re: Scripting problem: grouping and pipes
Could you attach a modified version of the script that does work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 07:26 AM
07-03-2002 07:26 AM
Re: Scripting problem: grouping and pipes
#!/bin/ksh
set -x
error_func()
{
[[ -n "$@" ]] && print -u2 "$@"
exit 1
}
echo Start
{
echo Start of braces
( false || error_func )
echo End of braces
}
echo Completed successfully
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 07:39 AM
07-03-2002 07:39 AM
Re: Scripting problem: grouping and pipes
There are two things I need from this part of my script - one is that I need for the error within the braces (i.e. the false) to be trapped and to cause an exit -1 from the script - the second is that I need all stdout from the braces to be piped through to another command (in my script it is mailx, in the test example it is cat -.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 08:25 AM
07-03-2002 08:25 AM
Re: Scripting problem: grouping and pipes
1) execute commands piping output to mailx
2) if error in any command, then exit script with return status of -1
Using "trap", you could do the following-
#!/usr/bin/ksh
export oops=/tmp/oops$$
rm $oops >/dev/null 2>&1
(
set -e
trap "touch $oops" ERR
echo start
false
echo end
) | mailx user@host.com
# See if any errors in prev commands
if [[ -f $oops ]] then
rm $oops
exit -1
else
exit 0
fi
Anything more complicated you may want to study up on shell programming...
Good Luck
-- Rod Hills