Solved

Need help writing a simple bash script

Posted on 2010-09-22
13
833 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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 500 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

617 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