Solved

Checking multiple systems with command "Top" using a Linux Script

Posted on 2008-06-12
4
292 Views
Last Modified: 2013-12-16
I am using the script below to check systems using the command top, but since Top requires "q" to terminate, it fails.

Is there a line I can put in the script to say q?

Here is the output I get:

=====================================================================
Host ops1corp at IP 192.168.1.236 is running the following services
=====================================================================
TERM environment variable not set.
 
=====================================================================
Host ops2corp at IP 192.168.1.237 is running the following services
=====================================================================
TERM environment variable not set.
 
=====================================================================
Host www1stg at IP 192.168.1.238 is running the following services
=====================================================================
TERM environment variable not set.

#!/bin/bash
 
# loop that checks each system in iprange specified
for i in $(seq 236 238)
do
  ip=192.168.1.$i
  host=$(ssh $ip -C hostname 2>&1)
  echo " "
  echo "====================================================================="
  echo "Host $host at IP $ip is running the following services"
  echo "====================================================================="
  ssh $ip "top"
done > topcheckfile 2>&1

Open in new window

0
Comment
Question by:Ryman1
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
http:// thevpn.guru earned 500 total points
ID: 21766911
as per
man top
use
top -n 1

This will run top for one iteration and stop it.
0
 

Author Comment

by:Ryman1
ID: 21772396
Thank shakoush.

However, I still get the error:

=====================================================================
Host ops1corp at IP 192.168.1.236 is running the following services
=====================================================================
TERM environment variable not set.

Any thoughts on why it says that and not the output of top?
0
 
LVL 19

Expert Comment

by:http:// thevpn.guru
ID: 21772582
YOu might want to investigate

TERM environment variable not set.

as which user are you logging in ?
0
 

Author Comment

by:Ryman1
ID: 21774238
I got to work using this small change: "top -bn 1"
#!/bin/bash
 
# loop that checks each system in iprange specified
for i in $(seq 236 238)
do
  ip=192.168.1.$i
  host=$(ssh $ip -C hostname 2>&1)
  echo " "
  echo "======================================================================"
  echo "Host $host at IP $ip is running the following services"
  echo "======================================================================"
  ssh $ip "top -bn 1"
done > topreport 2>&1
 
# manipulate file 'report_file' here...

Open in new window

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question