Solved

Script to telnet to various hosts & collect data.

Posted on 2002-03-06
7
216 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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.

746 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

10 Experts available now in Live!

Get 1:1 Help Now