shell script

Hi All

Have to write a shell script for the follwing tasks:

  1. Have to redirect three cmd outputs in three different files
    ex: sar -u 1 10 >date.sar.txt
    vmstat 1 10 >date.vmstat.txt
    iostat 1 10 >date.iostat.txt

    where date should be current system date as the output file name

Any help will be highly appreciated

Thanks

try this,

output of date would be used as such

cmd >  file."`date`".txt

Try this..,


Currentdate=`date +%Y%d%m`
echo $Currentdate

sar -u 1 10 > $Currentdate.sar.txt
vmstat 1 10 > $Currentdate.vmstat.txt
iostat 1 10 > $Currentdate.iostat.txt

or try this:

Currentdate=`date +%Y%d%m`
T="txt"
sar -u 1 10 > $Currentdate.sar.$T
vmstat 1 10 > $Currentdate.vmstat.$T
iostat 1 10 > $Currentdate.iostat.$T

Thank you guys for your help.

fish007, i tried your script which works fine. But i forgot to mention that i need the output of the 3 cmds of same time using the script not sequencial.

Thanks again

I still could not figure out how to run following 3 cmds parallel to take output of same time

sar -u 1 10 > $Currentdate.sar.txt
vmstat 1 10 > $Currentdate.vmstat.txt
iostat 1 10 > $Currentdate.iostat.txt

Can anyone help?

In that case, a common filename as mentioned in the previous post should be used

and that should be visible to the other 2 process as well.

if the process' are run in parallel and not as sequential process, you might encounter that the ouput of the 3 process just flush in in to the file and might be garbled, which needs to be parsed and refactored later.