Solved

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

Posted on 2008-06-12
4
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

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…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

734 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