- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Asynchronous command execution in a korn shell scr...
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
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
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
08-26-2011 12:35 PM
08-26-2011 12:35 PM
I'm writing a little script (a function that gets sourced into the current shell, actually) that calls a couple of commands asynchronously (command &). The script works fine, but I can't figure out how to suppress the job control information that gets printed to the terminal due to the asynchronous command calls.
Example:
$ gethostbyalc ai dev [1] 27621 [2] 27622 devg0d41 [2] + Done gethostbyalc ai dev [1] + Done gethostbyalc ai dev $
I figured out that the first lines that print the PID when the commands get backgrounded are going to stderr, so that's pretty easy to get rid of. The "done" lines, however, are being a little more stubborn. I figured out that if I turn off ksh's monitor mode with "set +m" before I run the function that the "done" lines go away. However, putting "set +m" in the function doesn't work.
Example turning monitoring off before calling the function (works):
$ set -x $ set +m + set +m $ gethostbyalc ai dev + gethostbyalc ai dev + OPTS= + APP=ai + LCYCLE=dev + + date +%Y%m%d%H%M%S APP_FIFO=/tmp/app_list_fifo.20110826142834 + + date +%Y%m%d%H%M%S LCYCLE_FIFO=/tmp/lcycle_list_fifo.20110826142834 + mkfifo /tmp/app_list_fifo.20110826142834 + mkfifo /tmp/lcycle_list_fifo.20110826142834 + exec + 3>& 2 + exec + 2> /dev/null devg0d41 + exec + + rm /tmp/app_list_fifo.20110826142834 + rm /tmp/lcycle_list_fifo.20110826142834 $
Example turning monitoring off inside the function (doesn't work):
$ set -x $ gethostbyalc ai dev + gethostbyalc ai dev + set +m + OPTS= + APP=ai + LCYCLE=dev + + date +%Y%m%d%H%M%S APP_FIFO=/tmp/app_list_fifo.20110826143118 + + date +%Y%m%d%H%M%S LCYCLE_FIFO=/tmp/lcycle_list_fifo.20110826143118 + mkfifo /tmp/app_list_fifo.20110826143118 + mkfifo /tmp/lcycle_list_fifo.20110826143118 + exec + 3>& 2 + exec + 2> /dev/null devg0d41 + exec + + rm /tmp/app_list_fifo.20110826143118 + rm /tmp/lcycle_list_fifo.20110826143118 + set -m [2] + Done gethostbyalc ai dev [1] + Done gethostbyalc ai dev $
Any ideas how to kill that output?
Kris Knigga
Solved! Go to Solution.
- Tags:
- background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011 12:40 PM
08-26-2011 12:40 PM
Re: Asynchronous command execution in a korn shell script
Full function source:
gethostbyalc () { set +m OPTS=$3 APP=$1 LCYCLE=$2 APP_FIFO="/tmp/app_list_fifo.$(date +'%Y%m%d%H%M%S')" LCYCLE_FIFO="/tmp/lcycle_list_fifo.$(date +'%Y%m%d%H%M%S')" mkfifo ${APP_FIFO} mkfifo ${LCYCLE_FIFO} exec 3>&2 exec 2>/dev/null gethostbyapp $1 > ${APP_FIFO} & gethostbylcycle $2 > ${LCYCLE_FIFO} & case ${OPTS} in "-w") comm -12 ${APP_FIFO} ${LCYCLE_FIFO} | awk 'BEGIN{ ORS=" " }{ print }' echo ;; *) comm -12 ${APP_FIFO} ${LCYCLE_FIFO} ;; esac wait exec 2>&3 exec 3>&- rm ${APP_FIFO} rm ${LCYCLE_FIFO} }
Kris Knigga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011 12:50 PM
08-26-2011 12:50 PM
Re: Asynchronous command execution in a korn shell script
@mkdlxk wrote:I figured out that the first lines that print the PID when the commands get backgrounded are going to stderr, so that's pretty easy to get rid of. The "done" lines, however, are being a little more stubborn. I figured out that if I turn off ksh's monitor mode with "set +m" before I run the function that the "done" lines go away. However, putting "set +m" in the function doesn't work.
So, what's wrong with doing the 'set +m' in the calling script, before you source the file containing the function you want to run in the background?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011 12:56 PM
08-26-2011 12:56 PM
Re: Asynchronous command execution in a korn shell script
That certainly would work, it's just kind of annoying to remember to have to do that.
Also, I can see cases where the function might be called interactively from the command line. Again, while it would work to remember to "set +m" before use, it would get old quickly.
The better solution, if possible, is figuring out how to turn off monitoring inside the function.
Kris Knigga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011 02:20 PM
08-26-2011 02:20 PM
Re: Asynchronous command execution in a korn shell script
>The better solution is figuring out how to turn off monitoring inside the function.
Or convert it from a function to a separate script?
I think the issue is that when the function returns, it resets +m. (I've had to add "set -x" to each individual function.)
And moving it to a separate script may fail the same way if the background processes still haven't finished before it returns.
You could always put a sleep there. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2011 06:48 AM
08-29-2011 06:48 AM
Re: Asynchronous command execution in a korn shell script
@Dennis Handly wrote:>...may fail the same way if the background processes still haven't finished before it returns.
You could always put a sleep there. :-)
I was hoping the wait would take care of any such issues, but apparently not.
Kris Knigga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2011 01:25 PM
09-08-2011 01:25 PM
SolutionUnfortunately, the best answer I could come up with was to do away with the fancy named pipes and just use temporary files. It does away with the need to background any processes and thusly eliminates unwanted output.
Kris Knigga