1833883 Members
1485 Online
110063 Solutions
New Discussion

Script Performance

 
SOLVED
Go to solution
Fernando Jose P de Souz
Regular Advisor

Script Performance

Hi,

i would like the output of my script in the same line, example:

Apr 27 2007 system 17 3 2 78


DATA=`date|awk '{print $2,$3,$6}'`
echo $DATA >> /tmp/perf_cpu.txt
sar -uM 1 1 | tail -1 >> /tmp/perf_cpu.txt

4 REPLIES 4
Aussan
Respected Contributor
Solution

Re: Script Performance

Hi Fernando

here it is

# DATA=`date|awk '{print $2,$3,$6}'`.
# TEST=`sar -uM 1 1 | tail -1`
# echo $DATA $TEST > /tmp/perf_cpu.txt

# more /tmp/perf_cpu.txt
Apr 27, PM. system 0 0 0 100



Regards

Aussan
The tongue weighs practically nothing, but so few people can hold it
Aussan
Respected Contributor

Re: Script Performance

Hi Fernando

here it is

# DATA=`date|awk '{print $2,$3,$4}'`.
# TEST=`sar -uM 1 1 | tail -1`
# echo $DATA $TEST > /tmp/perf_cpu.txt

# more /tmp/perf_cpu.txt
Apr 27, 2007 system 0 0 0 100



Regards

Aussan
The tongue weighs practically nothing, but so few people can hold it
Fernando Jose P de Souz
Regular Advisor

Re: Script Performance

Thanks.
A. Clay Stephenson
Acclaimed Contributor

Re: Script Performance

All you really need to do is change this line:
echo $DATA >> /tmp/perf_cpu.txt
to this:
echo "${DATA} \c" >> /tmp/perf_cpu.txt

However, you really don't need awk to format the date output:
so I would change:
DATA=`date|awk '{print $2,$3,$6}'`
to :
DATA=$(date '+%b %d %Y')

so that a better version of your script should be very close to this:

---------------------------------
#!/usr/bin/sh
OFILE=/tmp/perf_cpu.txt
DATA=$(date '+%b %d %Y')
echo "${DATA} \c" >> ${OFILE}
sar -uM 1 1 | tail -1 >> ${OFILE}
If it ain't broke, I can fix that.