SybaseUk
asked on
Need help writing a simple bash script
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/io stat.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.
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/io
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.
ASKER
No, that gives me funny output in my iostat.txt file
Try
( date ; iostat -xn 3 10 ) >> /syb/homedir/monitoring/io stat.txt
wmp
( date ; iostat -xn 3 10 ) >> /syb/homedir/monitoring/io
wmp
.. or rfportilla's solution, a bit modified -
echo "$(date) $(iostat -xn 3 10)" >> /syb/homedir/monitoring/io stat.txt
echo "$(date) $(iostat -xn 3 10)" >> /syb/homedir/monitoring/io
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..
echo "$(date) $(iostat -xn 1 1)" >> iostat.txt
3 10 will run it 10 times every 3 second..
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
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/
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
*/15 * * * * echo "$(date) $(iostat -xn 1 1)" >> /root/iostat.txt
ASKER
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?
iostat -xn 3 10
this command will run every 15 mins by putting it into crontab, as:
15 * * * * * /syb/homedir/mon/run_perf.
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?
in that case the solution id 33733449 by woolmilkporc is perfect for you.
One single timestamp for every 15 minute run ( i.e. one timestamp per 10 iterations) - that's one of my solutions #33733065 or #33733088
ASKER
can u be a bit clear please? I am not that familiar with EE....where are your solutions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thank you...that worked fine.
echo $(date) $(iostat -xn 3 10) >> /syb/homedir/monitoring/io