Operating System - Linux
1753416 Members
5161 Online
108793 Solutions
New Discussion юеВ

Re: unable to use sar -A -o in a script

 
Dodo_5
Frequent Advisor

unable to use sar -A -o in a script

I am using sar command in my script for system montoring.So I am running my script as background process.
But whenever i am starting my script as a background process,it's showing 'DONE' in the next second but giving the output.
Can anyone help me in this regard? how to get all sar data using 'sar -A -o outfile interval count' using a shell script?

But when i am running sar -A -o outfile interval count > /dev/null &
in the commandline it's working fine.

I have attached the script ....
4 REPLIES 4
Rob Leadbeater
Honored Contributor

Re: unable to use sar -A -o in a script

Hi,

When you say background process, do you mean the script is being kicked off from the cron ?

If so, then you may well have to specify the full path to the commands you're using, as cron's environment may not be the same as yours...

Cheers,

Rob
Dodo_5
Frequent Advisor

Re: unable to use sar -A -o in a script

Thanks for ur help.....
No i am running the script as ./script.ksh &
but the sar process is not happening properly.
but mpsat,prstat all are going on fine in that script(prstat 5 6 >> output.txt)
Also sar -u 5 6 >>sar_output is fine.
but only sar -A -o output 5 6 > /dev/null & is not working in that script.

Is there any other way to write a script for getting the same output of sar -A -o output 5 6 > /dev/null &
Stuart Browne
Honored Contributor

Re: unable to use sar -A -o in a script

My quick guess would be because it's the last line of the script.

The 'sar' is getting put into the background, yes. But then the script is ending.

Using KSH on OSR5 boxes, this usually meant that the backgrounded processes would get HUP'd by the ending shell.

If you really do wan to keep the 'sar' running after the KSH ends, nohup it, as well as put it into the background, or just 'exec' it, without backgrounding it.
One long-haired git at your service...
Dodo_5
Frequent Advisor

Re: unable to use sar -A -o in a script

can you give add the lines required for modification of the script.I have changed a bit to the code myself.
I have used sar -A -o output 5 5 > junkfile &
for this script is creating two output file now.one is binary sar output 'output' file & another file is 'junkfile' .So is it proper to use like that or any other way to optimize the script?
Is there any other way to do it?