Solved

Script to telnet to various hosts & collect data.

Posted on 2002-03-06
7
229 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
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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 80 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
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.

809 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