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
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

861 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