LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-06-2005, 10:37 AM   #1
pymehta
Member
 
Registered: Jan 2004
Posts: 54

Rep: Reputation: 15
Shell Redirection Delay


Quoted anonymous :
"When doing `./executable > file.txt`,
the file is not continuously written to; ie. the program output goes to some sort of buffer which is transferred to the file in chunks after quite a long time or when the execution of the file stops. Is there any way to make the updation of the file more frequent?"
 
Old 04-07-2005, 08:01 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
why?
 
Old 07-21-2009, 04:07 PM   #3
hemlockz
LQ Newbie
 
Registered: Sep 2005
Posts: 13

Rep: Reputation: 0
BUMP the old post. I have the exact same question , this came up in the search.
 
Old 07-21-2009, 04:47 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
why?
 
Old 07-21-2009, 05:14 PM   #5
hemlockz
LQ Newbie
 
Registered: Sep 2005
Posts: 13

Rep: Reputation: 0
I am trying to make a script to capture output from hcidump, use a sed substitution to filter out extra data from hcidump, and I tee that to a file on a SSD, and to stdout on the screen. I want to see realtime data on the stdout since this application is detecting new devices all the time, and visual feedback is necessary for good antenna placement in the field. Without the tee command I see the filtered output from sed on stdout in real time. As soon as I add a tee or try and redirect it to a file I start seeing a delay.
 
Old 07-21-2009, 06:08 PM   #6
hemlockz
LQ Newbie
 
Registered: Sep 2005
Posts: 13

Rep: Reputation: 0
Okay just tell me a better way to script it than. I'm not an expert.

sudo hcidump -Vt | sed -n 'N;s_<PATTERN>_<REPLACE>_p'|tee -a $FILENAME &

Last edited by hemlockz; 07-22-2009 at 12:26 PM.
 
Old 07-21-2009, 08:47 PM   #7
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
The sed 'w' command appends the contents of the pattern space to a file.
http://www.gnu.org/software/sed/manu...Other-Commands
I don't have 'hcidump', however this method works using 'free -k -s 1' instead of 'hcidump'
Code:
sudo hcidump -Vt | sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $FILENAME"
 
Old 07-21-2009, 09:02 PM   #8
GaijinPunch
Member
 
Registered: Aug 2003
Location: Tokyo, Japan
Distribution: Gentoo
Posts: 130

Rep: Reputation: 22
If I'm not mistaken this is on a per-program basis. tail will dump ever 1 second, for example, while most other programs will not until the buffer is full.
 
Old 07-22-2009, 12:50 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
No, I've seen people confused by 'tail -f blah' not show any output. The system usually uses some buffering by default.

If its your own code you can disable buffering.

Here's a good explanation: http://perl.plover.com/FAQs/Buffering.html.
 
Old 07-22-2009, 12:25 PM   #10
hemlockz
LQ Newbie
 
Registered: Sep 2005
Posts: 13

Rep: Reputation: 0
This is great! This works perfect because it writes unbuffered to the file, and still displays the output on stdout. Thank you guru.

One minor follow-up question... I have to put the literal path of the output file. When I use
Code:
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w ~/Desktop/$FILENAME"
I get a "could't open file" error. If I replace the ~ with /home/user it works well. Is there a way to make ~? its not a big deal but would be nice for portability.

Thank you also for the perl solution. That seems like it would work well too. I may end up converting this sh script to perl if it gets any more complicated, so that was useful info.

Quote:
Originally Posted by Kenhelm View Post
The sed 'w' command appends the contents of the pattern space to a file.
http://www.gnu.org/software/sed/manu...Other-Commands
I don't have 'hcidump', however this method works using 'free -k -s 1' instead of 'hcidump'
Code:
sudo hcidump -Vt | sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $FILENAME"

Last edited by hemlockz; 07-22-2009 at 12:27 PM.
 
Old 07-22-2009, 07:31 PM   #11
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Code:
# The Bash shell variable $HOME can be used instead of ~
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $HOME/Desktop/$FILENAME"

# This is a way of getting ~ to work
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $(echo ~)/Desktop/$FILENAME"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how-to: repeat OR iterate shell OR bash command delay OR interval admarshall Linux - General 5 07-18-2005 10:47 PM
shell script output redirection goral.j Programming 3 01-27-2005 05:34 AM
Delay in shell script or alias jeopardyracing Linux - Newbie 6 09-21-2004 08:07 PM
redirection in C pantera Programming 2 08-11-2004 01:06 PM
I/O redirection in a shell script gladeiator Programming 1 11-27-2003 01:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration