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

I am working on a script which will poll a number of devices on my network, and gather a certain set of information. I am using ssh as the primary means of communication between the "base node" and the remote devices.. I am using public key authentication so I don't have to worry about logging into each device. The problem is that some of the devices don't have my public key and/or have expired root passwords, so they ask for a login prompt. I want to be able to ignore this and just mark it up as "ssh is broke" for the purpose of this poll. Another nail in the coffin is that I'm stuck with perl 5.005 (without Thread.pm). Every way I've tried to redirect the output fails, and I can't use any other modules.

Can you help?

- I know nothing....

Replies are listed 'Best First'.
Re: Ignoring ssh login request?
by ptkdb (Monk) on Oct 17, 2003 at 22:49 UTC
    Have you tried using the alarm(timeout) function?
    # psuedo code alarm(someresonabletime) connect ; # blocks completely if you're prompted for PW # check error status and if SIG{ALARM} was called alarm(0) ; # disable pending alarm if( we got an EINTR or our SIG{ALARM} was called ) { broken ssh } ## ## Connected ##
    The only problem is that you won't be able to differentiate between a broken ssh and a system that's slow in responding.
Re: Ignoring ssh login request?
by iburrell (Chaplain) on Oct 17, 2003 at 21:50 UTC
    I couldn't find a way to prevent ssh from talking with the terminal for password prompts. One trick is to disable password authentication. This won't help with missing host key prompting but it eliminates passwords prompts and fails when it can't authenticate.
    ssh -o PasswordAuthentication=no host
      I hadn't thought of that. I like the idea of being able to disable it from a "1 time trial" point of view. I may end up going that route.

      - I know nothing....
Re: Ignoring ssh login request?
by pzbagel (Chaplain) on Oct 18, 2003 at 04:08 UTC

    OpenSSH has the Batchmode option (-o Batchmode=yes) which disables interactive prompts. Also look at using Net::SSH:Perl to gain more control of your ssh'ing.

    Later

      I didn't know about the Batchmode, and actually, disabling the PasswordAuthentication on the client side worked. I have had problems compiling Net::SSH::Perl (actually some of the dependent modules), so as much as I would like to use it, it have been unable to.
      - I know nothing....
Re: Ignoring ssh login request?
by idsfa (Vicar) on Oct 18, 2003 at 00:39 UTC

    ssh is reading and writing directly to /dev/tty. In order to control this, you need to do a bit of hokey pokey with setsid, open a new tty for your new process group, and then dup those file descriptors in your parent to pipes that speak to your child. It's a hassle.

    I ran across this trying to do y2k testing with sudo, which does the same thing. I'll update this node with code if I can find it ...

    Updated:
    Admittedly, this isn't perl, but you should be able to adapt ...

    pipe(toslave); pipe(frslave); if (fork() == 0) { int fd; close(0); dup(toslave[0]); close(1); dup(frslave[1]); (void)setsid(); /* become session leader and */ /* lose controlling tty */ fd = open("/dev/console", O_RDWR); #ifndef hpux (void)ioctl(fd,TIOCSCTTY,0); #endif free(argv[0]); argv[0] = (char *)malloc(5 * sizeof(char)); sprintf(argv[0],"ssh"); execv("/usr/bin/ssh", argv); fprintf(stderr,"Bad exec (%u)\n", errno); exit(0); } write(toslave[1],PASSWORD, strlen(PASSWORD)); if (! strncmp("-v", argv[1])) exit(wait(NULL)); if (! strncmp("-k", argv[1])) exit(wait(NULL)); num=read(frslave[0],buf,359); buf[num]='\0'; printf("%s", buf); exit(wait(NULL)); }

    I'll perlify later this weekend ...


    Remember, when you stare long into the abyss, you could have been home eating ice cream.