Solved

Script to telnet to various hosts & collect data.

Posted on 2002-03-06
7
225 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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 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…
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.

773 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