Solved

Need help writing a simple bash script

Posted on 2010-09-22
13
820 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
 
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:ddsh79
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:ddsh79
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:ddsh79
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mac telnet client seems to skip part of login script? 12 55
sum13 challenge 24 78
only14 challenge 19 64
EXCHANGE, ACTIVE DIRECTORY 4 59
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now