Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Is this bug still active in RHEL 2 30
Best way to split and output to csv in bash 2 30
Sendmail STARTTLS error 37 43
nagios 1 12
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

758 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

21 Experts available now in Live!

Get 1:1 Help Now