Solved

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

Posted on 2008-06-12
4
289 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anti-Spam SMTP Proxy Server (@SSP) 7 80
bad ownership or modes for chroot directory 6 63
My bash alias isn't executing 5 47
Anti-virus for Linux Server 15 121
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now