Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

One of my duties is to rlogin to a machine and do a df -k , top ,ps -ef ,mailq and a few others. I know how to write a script like this
system ("rlogin\n"); $var1 = `df -k`; print "$var1\n";
Problem for me is after the rlogin system () funtion I get asked for a password ,when I type in the passwd nothing happens until I exit and then I get the output of df -k for my box instead of the target box.
How can I pass the passwd to the term and get df -k to run on the target box.
I am trying to automate this because I have over 200 boxes to do this for.Thanks for you help in advance
Kevin G.

Replies are listed 'Best First'.
Re: rlogin followup
by archon (Monk) on Mar 20, 2001 at 05:21 UTC
    Given your question, I'm going to recommend you look into setting up Big Brother or Spong.

    If you really want to write the thing yourself, though, you need to read up on Perl a lot more. Just because you execute an rlogin command in with system(), that's not going to make your Perl script start running commands on that system when you use backticks. You could use $var1 = `rsh remotemachine df -k`

    You should probably at least look through spong if you want some ideas of how to implement this on your own, though.

Re: rlogin followup
by meonkeys (Chaplain) on Mar 20, 2001 at 05:31 UTC
    (ducking arrows and hot tar...)
    Why do you want to use Perl? This sounds like a UNIX sys admin 101 question. Shell would probably be best suited to handle a bunch of system calls. As for authentication, NIS or LDAP would be best suited for a grandiose remote authentication schema, rather than a)having the same password for every box, or b)having 200 hosts.equiv or .rhosts files to run rsh passwordless. Here's another option: get NetSaint. It's an awesome monitoring package written in C for linux platforms, but you can get the source and try it anywhere. A quick demonstration would probably convince a sys admin that it's worth installing.

    Here's the really Perlish solution: Read Perl for System Administration
Re: rlogin followup
by larsen (Parson) on Mar 20, 2001 at 05:23 UTC
    I have never used it, but I think you could download and read the documentation of Expect
Re: rlogin followup
by BlueLines (Hermit) on Mar 20, 2001 at 10:46 UTC
    I definitely think that this is a job for Big Brother. rlogin is dirty because it's not encrypted. ssh is safer and can be used to execute remote commands. But either way, you should use the Expect module. One of the tutorials in the package actually covers this exact question.

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
Re: rlogin followup
by Beatnik (Parson) on Mar 20, 2001 at 14:35 UTC
    if you dont NEED to use rlogin, Net::SSH::Perl allows you to login and execute pretty easily.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.