Shell Script Problem

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Shell Script Problem

Post by jromariz »

Hi Alex,


I´m facing a problem when writing shell cript for a LINUX box. This is the cript I´m using:

#!/bin/sh
CPUUSED=`top -n 1 | grep total | awk -F"%" '{print 100 - $7}'`
echo $CPUUSED| awk '{print "ScriptRes:OK:"$1":%"}'

I´m trying to get the amount of used cpu on the machine. The problem is that when I try the script on Script Manager, the reply does not came with the value.

Thanks for helping.

Regards,

Jromariz.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Are you sure "top -n 1 | grep total" prints CPU usage?

On my Linux system such command produces 3 lines, non of them contains CPU Usage and non of them contains "%".
As result CPUUSED variable contains 3! lines
100
100
100
That's probably why Reply value is empty - variable prints 3 lines instead of 1

Regards
Alex
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,

Running the script direclty on the console of the box show correct results for me. The problem is when I run it using script manager. Get empty value as result.

Regards,

Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,

The correct command is:

top -n 1 | grep total |awk '{print $8}'

Regards,

Jromariz.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Its not correct on my system.
So, now it works (on your system)?

Regards
Alex
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

No. It is working when I run it on the box but not with sciprt manager where I still get empty results.


Regards,


Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,

To make it more clear:

- When I run the script on the machine, I get correct result:

ScriptRes:Ok:47.9

- When I run on script manager usign the agent on the same machine I get:

----------
- Status: Ok
- Reply:
----------


Regards,


Jromariz.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

May be result contains non-printable charactes (ESC sequences)? Its Ok for user output but not for HostMonitor.
May I have telnet access to your system?

Regards
Alex
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,

The system is not connected to the Internet :( . Is there any way to find out if the result contains non-printable charactes :D? I´m using exactly the same fprint command format that is used in other scripts that came with hostmon.

Thanks for helping,

Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,


This is the script I´m using:

#!/bin/sh
top -n 1 | grep total | awk '{load=(100 - $8); printf("ScriptRes:Ok:%2.2f \%\n",load); exit;}'

Running it on the machine I get the correct result:

ScriptRes:Ok:11.60 %
Running it on hostmon using the local agent on the same machine I get:

[09:03:52] Script started, no results received
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Sorry,

The 8) should be replace by 8 and ).


Regards,

Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,


Is it possible to add some kind of error log to the script manager. It would make troubleshotting much more easy.


Regards,

Jromariz.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Is there any way to find out if the result contains non-printable charactes
Redirect output to file and use some editor that shows file as is
E.g.
top -n 1 | grep total >1.txt
vi 1.txt


Regards
Alex
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,


I already did this redirection and found no non-printable characters on the output.


Jromariz.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Can you send this file to me?
---------
top -n 1 | grep total >1.txt
./your_script.sh >2.txt
---------
and send 1.txt, 2.txt to support@ks-soft.net

Regards
Alex
Post Reply