LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-13-2009, 02:32 AM   #1
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Rep: Reputation: 148Reputation: 148
Write the data in to a file while running command


free -k -s 1 | grep --line-buffered Mem | awk '{print $3}' > usedmem.txt

what is the wrong with this set of commands because this wont write the output in to the usedmem.txt file
 
Old 07-13-2009, 05:15 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Not sure, but this works.

Code:
free -k -s 1 | awk '/Mem/{print $3;fflush()}' > usedmem.txt
 
Old 07-13-2009, 07:53 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by kirukan View Post
free -k -s 1 | grep --line-buffered Mem | awk '{print $3}' > usedmem.txt

what is the wrong with this set of commands because this wont write the output in to the usedmem.txt file
Take off the redirect and you'll see the command works fine. I think the issue is that it keeps running and you probably have to wait until a buffer fills up before it will actually write to the file.
 
Old 07-13-2009, 12:37 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by pixellany View Post
Take off the redirect and you'll see the command works fine. I think the issue is that it keeps running and you probably have to wait until a buffer fills up before it will actually write to the file.
Indeed ... if he adds the fflush from my awk bit to his
it works as expected. It's just that the grep is unnecessary
to begin with. ;}


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
I (sometimes) cant write my program file when a copy of it is running foof Linux - Newbie 6 11-13-2008 05:17 PM
To write a script file to check the running exe in LINUX platform udhaya Linux - Newbie 1 01-31-2008 09:13 AM
is there any shell command to read and write data from parallel and serial port? baosheng Linux - Hardware 2 01-13-2007 09:35 PM
How to write down result of performance of a command in a file ukrainet Linux - Newbie 3 12-08-2004 10:51 AM
tcpdump -w command doesn't write to file andykerouac Linux - Networking 2 03-03-2004 08:10 AM


All times are GMT -5. The time now is 04:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration