?
Solved

Script to telnet to various hosts & collect data.

Posted on 2002-03-06
7
Medium Priority
?
248 Views
Last Modified: 2010-04-21
I need help making a script that will read the hosts from a file called "nodes" and telnet to each host and perform some action, say grep, and redirect the output to a file on the box where the script ran from.

Im cant seem to get the loop to telnet to each file in the node.

for f in nodes;
do
   rlogin -l user $f
done
0
Comment
Question by:RudePuppyDog
[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
7 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 6846188
You should use ssh or rsh to do this job, rsh is not secure by the way.
0
 
LVL 6

Expert Comment

by:bira
ID: 6847483

     while read host
      do
      rsh $host grep >> grep.log
      done < nodes
0
 

Author Comment

by:RudePuppyDog
ID: 6847807
while using

    while read host
     do
     rsh $host grep >> grep.log
     done < nodes

I get a permission denied error.  Is there any way to specify a password with rsh?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RudePuppyDog
ID: 6848279
Fixed the permission denied error .. problem was with rhosts file.  Problem I have now is with the command that I want to run on each node.

Q1: Can I run more than 1 command using rsh?
Q2: With the script that i have, the command "uname" is only running on the 1st entry in the filename node.

rm grep.log
touch grep.log
while read host
do
  rsh -l maint $host uname -a >> grep.log
done < nodes
0
 
LVL 5

Accepted Solution

by:
Nisus091197 earned 320 total points
ID: 6850037
Hi,

This is a little neater and shows how to run several commands:

> grep.log
for host in `cat ./nodes`; do
 echo "Reporting on server $host" >> ./grep.log
 rsh -l maint $host "date; uname -a; df -k; vmstat 5 5" >> ./grep.log
 echo "\n\nEnd of report for server $host\n\n" >> ./grep.log
done

Regards, Nisus
http://www.omnimodo.com
0
 

Author Comment

by:RudePuppyDog
ID: 6850942
Works great ... Thanx.
0
 
LVL 5

Expert Comment

by:Nisus091197
ID: 6850999
excellent, I didn't even test it.

This is the type of thing I do all the time in a large server environment.

Extra tip:  Keep a list of machines centrally and use that list in your scripts.  I usually keep files like that in /usr/local/files.

Here's a ping test (again not tested but should work).

for i in `cat /usr/local/files/machines.solaris`; do
  /usr/bin/echo "pinging $i ... \c"
  ping $i 2 > /dev/null 2>&1
  if [ $? -ne 0 ]; then
    /usr/bin/echo "ALERT - cannot ping $i"
  else
    /usr/bin/echo "host $i okay"
  fi
done
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

770 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