Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help writing a simple bash script

Posted on 2010-09-22
13
Medium Priority
?
837 Views
Last Modified: 2013-12-26
Hi Guys,

I need to collect iostat information every 15 minutes, and also print the timestamp for each collection interval. I am planning to write a simple shell script that will output iostat to a file and also collect the timestamp for each iostat interval...I will then add this to crontab to run every 15 mins...this is what I have so far:

vi run_perf.sh
iostat -xn 3 10 >> /syb/homedir/monitoring/iostat.txt

I'm not used to writing scripts but I want is for my script to append iostat to a file upon every execution and also print timestamp...

Any help is welcome!

Many Thanks.
0
Comment
Question by:SybaseUk
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 9

Expert Comment

by:rfportilla
ID: 33732926
Does this work?

echo $(date) $(iostat -xn 3 10) >>  /syb/homedir/monitoring/iostat.txt

0
 

Author Comment

by:SybaseUk
ID: 33732966
No, that gives me funny output in my iostat.txt file
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33733065
Try
( date ; iostat -xn 3 10 ) >> /syb/homedir/monitoring/iostat.txt
wmp

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33733088
.. or rfportilla's solution, a bit modified -
echo "$(date)  $(iostat -xn 3 10)" >>  /syb/homedir/monitoring/iostat.txt
 
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33733414
the solution from woolmilkporc will work but there is a slight tweak to the solution.

echo "$(date) $(iostat -xn 1 1)" >> iostat.txt

3 10 will run it 10 times every 3 second..
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33733449
OK,
if 10 iterations every 3 seconds including 10 timestamps are desired, you could do this -
for i in $(seq 1 10) ; do (date ; iostat -xn 1 1) >>/syb/homedir/monitoring/iostat.txt; sleep 3; done
 
 
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33733590
i think author wants to collect one sample every 15 minutes so adding this to cron as below will do

*/15 * * * * echo "$(date) $(iostat -xn 1 1)" >> /root/iostat.txt
0
 

Author Comment

by:SybaseUk
ID: 33733617
What I want is 10 iterations and 3 seconds apart so the iostat command that I want is:

iostat -xn 3 10

this command will run every 15 mins by putting it into crontab, as:

15 * * * * * /syb/homedir/mon/run_perf.sh


the only problem is that I do not know how to add a timestamp for each collection interval (i.e. a timestamp for every 15 minute run)....

any ideas?
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33733657
in that case the solution id 33733449 by woolmilkporc is perfect for you.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33733691
One single timestamp for every 15 minute run ( i.e. one timestamp per 10 iterations) - that's one of my solutions #33733065 or #33733088
 
0
 

Author Comment

by:SybaseUk
ID: 33733741
can u be a bit clear please? I am not that familiar with EE....where are your solutions?

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 33733792
( date ; iostat -xn 3 10 ) >> /syb/homedir/monitoring/iostat.txt
echo "$(date)  $(iostat -xn 3 10)" >>  /syb/homedir/monitoring/iostat.txt
The numbers I mentioned represent Comment IDs found in the header bar of the respective comment (preceeding "Author:")
 
 
0
 

Author Comment

by:SybaseUk
ID: 33733990
ok thank you...that worked fine.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question