piping and backgroud processes (daemons)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting piping and backgroud processes (daemons)
# 1  
Old 06-19-2008
piping and backgroud processes (daemons)

Hello to all,
I've a strage problem here:
a perl script that parses the output of sar -q 300 0 (one line of performace data each 5 min. infinately) works fine from the CLI. It processes one line output every 5 minutes.
If i disconnect it from the terminal (executing it with cron, nohup startporc etc...) no output is processed until sar has completed (using sar -q 1 20).
then all 20 llines output are processed at the same time.

Code
Quote:
open (SAR,"/usr/bin/sar -q 1 4&|") or die "Cant open sar" ;
while (<SAR>){
chomp;
# write the output into a rrd database
}
close (SAR);
the script is supposed to run as "demon" in the backdround to ubdate
performance reports every 5 minutes, so i need to process the output just in time.

As far as i foun out it is not a Perl problem rather than the way linux handels pipes on processes not running on a terminal.

any ideas ?
# 2  
Old 06-19-2008
What you are looking for is to set $| = 1; on the currently selected file handle (by default STDOUT). $| also known as $OUTPUT_AUTOFLUSH and also $AUTOFLUSH turns OFF buffering when set and so you will see the results of every print as it happens instead of when perl figures it's time to flush the output buffer. Buffering is ON in perl by default. If you are printing to STDOUT you have only to do a $| = 1; somewhere before your while loop. If you print to some other handle be sure to select(HANDLE); before you assign to $|, etc.
# 3  
Old 06-20-2008
works fine thx.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running commands in backgroud

I have a small question may be this will be discussed before I have two files file1 and file2 with huge data and I am running the commands as cat file1 |sort & cat file2 |sort & If the session is got disconnected or logout will this command run in background, or shall we use nohup (3 Replies)
Discussion started by: morbid_angel
3 Replies

2. HP-UX

status of daemons

Hi there all, Hey, is there a way to get the status of all daemons running on a HPUX? in an easy way? Like the same way how to vieuw the status of packages in cmviewcl. Thanks! (1 Reply)
Discussion started by: draco
1 Replies

3. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (5 Replies)
Discussion started by: albertashish
5 Replies

4. Shell Programming and Scripting

daemons definition

hi there, can somebody give me a definition for daemons, or example what are they !! and what the use for? i've done some research and all what i found is /etc/... or /usr/bin/... and i haven't quietly got the concept. any ideas !! Thanks. (5 Replies)
Discussion started by: new2Linux
5 Replies

5. UNIX for Dummies Questions & Answers

Starting daemons at reboot.

I rebooted my server (solaris 5.8) and I had to manually start the cron and mailx daemons. How do I get these to automatically start at reboot? Thanks in advance. (2 Replies)
Discussion started by: shorty
2 Replies

6. Linux

A doubt on Daemons

Hi there! I'm a bit curious on something about Daemons.... Supose you have two processes say A and B, where B is a daemon. A is totally independent from B. Is there a way for A to find out B's return code? Is there a way for A to find out when B ends? Thanks! (4 Replies)
Discussion started by: marioh
4 Replies

7. UNIX for Dummies Questions & Answers

Daemons

MYSQL-daemon don't started automatically by system-start. And same trouble with httpd too. I have SuSE 8.0. What can I do ? Thanks.... (6 Replies)
Discussion started by: Pennywize
6 Replies

8. UNIX for Advanced & Expert Users

backgroud process

Hi experts How to write a shell program(sh) that running on the backgroud when foreground processing something, such as prompt ....... till the background process finished. thx (4 Replies)
Discussion started by: trynew
4 Replies

9. IP Networking

DNS daemons

Does anyone know the command to start the DNS Daemon. I looked in the /etc/init.d/inetsvc file and it tells me what the text should look like. When I go to open the corresponding files they are encoded and I can't read them. So is there a command that will start the DNS daemon? If... (8 Replies)
Discussion started by: Deuce
8 Replies
Login or Register to Ask a Question