- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Background process in a while-read loop
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
08-16-2004 06:47 PM
08-16-2004 06:47 PM
Background process in a while-read loop
I have a configuration file that is parsed:
grep pattern configfile | while read prc
do
start_program $prc > /dev/null 2>&1 &
done
This does not work anymore
- Tags:
- background
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 07:12 PM
08-16-2004 07:12 PM
Re: Background process in a while-read loop
try redirecting your standard error and standard output to a log file instead of /dev/null. It should give some details there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 08:22 PM
08-16-2004 08:22 PM
Re: Background process in a while-read loop
I think that your problem is that the file is parsed only once.
TO have it work, try this:
tail -f configfile| grep pattern | while read prc
do
start_program $prc > /dev/null 2>&1 &
done
THis works IF you are just adding lines to your files, for example with a
echo "prog" >> configfile.
But if you want to run a program, each time you modify a line i that file, it's more difficult.
You have to write a deamon that check the file ans parse it.
Is this that you want ?
Regards,
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 08:22 PM
08-16-2004 08:22 PM
Re: Background process in a while-read loop
grep pattern configfile | while read prc
do
start_program $prc > /dev/null 2>&1 < /dev/null &
done
Although admittadly, a backgrounded process shouldn't be able to read from stdin as far as I'm aware..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 08:27 PM
08-16-2004 08:27 PM
Re: Background process in a while-read loop
set -x
grep pattern configfile | while read prc
do
start_program $prc > /dev/null 2>&1 &
pid=$!
echo "Process ID: $pid"
ps -ef | grep -v grep | grep -w $pid
done
It will give the behaviour / problem to you more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 10:32 PM
08-16-2004 10:32 PM
Re: Background process in a while-read loop
This has been working before, but now, with another revision of ksh (82.10.2.61) it does not work anymore.
The script works, so that a couple of processes are started, but the script does not terminate. It does not reach the line following the "done" command.
A "nohup start_program ..." does not work either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 10:43 PM
08-16-2004 10:43 PM
Re: Background process in a while-read loop
grep pattern configfile | {
while read prc
do
start_program $prc > /dev/null 2>&1 &
done
}
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 11:04 PM
08-16-2004 11:04 PM
Re: Background process in a while-read loop
It is good to use exit 0 statement on processed function and main program.
exit 0 statement is needed on your shell functions and main program.
And more it's good to have your script and debug input to try on your problem.
Use set -x to start the script and do as,
start_program $prc > /tmp/testlog.log 2>&1
so that start_program informations will be there in /tmp/testlog.log to track the problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 11:28 PM
08-16-2004 11:28 PM
Re: Background process in a while-read loop
grep pattern configfile | while read prc
do
start_program $prc /dev/null 2>&1 &
done
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2004 11:46 PM
08-16-2004 11:46 PM
Re: Background process in a while-read loop
if it never reach the "done", what is the content of the config file ?
Maybe there is some garbage..
Also, check the canghelog for the ksh. Since you mentioned a change in it, maybe there is a different behaviour then expected.
HTH,
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2009 01:04 AM
01-16-2009 01:04 AM