LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2008, 02:11 AM   #1
Keshav murthy
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Rep: Reputation: 0
Writing value to a file using shell scripting


Hello,
I want know is it possible to write an output to a file using shell scripting
i have a value which is refreshing every minute i want to write or save that value in the hard disk..is it possible to do that using shell scripting??

Regards,
Keshav
 
Old 09-25-2008, 02:17 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use redirection, e.g.

echo "Stuff" > file

will write the string "Stuff" to the file called "file" (obviously you can replace the "echo "Stuff"" with whatever is generating output). If this isn't what you want to do, please explain in more detail.
 
Old 09-25-2008, 03:06 AM   #3
nitin_nitt
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
echo "stuff" >> file

A single > will overwrite the file, >> will append to it.
 
Old 09-25-2008, 03:24 AM   #4
Keshav murthy
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Original Poster
Rep: Reputation: 0
No my question was, suppose i want to list the CPU utilization or Memory usage of all the active process and i want it to write the values to a file and save it in a hard disk, that file should refresh as the % CPU utilization or memory usage changes.
 
Old 09-25-2008, 04:26 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you want a current reading, you can just use ps and don't need a file. If you want to track cpu usage, you can use top or vmstat and redirect the output to the file or have the output displayed in the console and use the "tee" command to also write the output to a file (use the -n(vmstat)/-b(top) option). A simple sed command could be used so that the output is comma separated values that you can enter into Open Office Calc.

Last edited by jschiwal; 09-25-2008 at 01:32 PM.
 
  


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
[SOLVED] shell scripting: How can I increment a file by number dv502 Programming 11 08-27-2010 08:43 AM
How to close a opened file using shell scripting Ashok_mittal Programming 1 01-02-2008 06:51 AM
file formatting via shell scripting athreyavc Programming 2 10-09-2007 03:55 AM
perl scripting, writing to more than one file homey Programming 2 06-28-2006 03:56 PM
Shell scripting from java file karthiknataraj Linux - General 1 02-08-2003 04:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 AM.

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