Solved

Script to telnet to various hosts & collect data.

Posted on 2002-03-06
7
237 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
Independent Software Vendors: 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

733 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