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

At first I didn't think this was a perl problem (and it still might not be), however I'm quickly running out of non-perl things that could cause this problem

I have a script that runs on boot. It basically takes some info, puts it into a text file, and then puts the text file on another box.

The line of code that produces the stty: standard input: Invalid argument error is

system("sudo -u username scp /tmp/bootbox21.txt mybox.mydomain:/export +/home/username/");

I first though this was caused by sudo trying to run one of the .bashrc or .bash_profile files. In /etc/bashrc I commented out the two lines which have an stty command, but that didn't help. Actually I didn't think it would since, they're only run if it is a login shell. There is no /etc/bash_profile. I then thought that ~/username/.bash_profile might have some problem (there is no .bashrc file for the user). I eventually went so far as to completely rename it so it wouldn't be found. Still no luck.

So now I'm starting to wonder if it isn't some weird perl gotcha with the system command using sudo. Can anyone help with this?

Replies are listed 'Best First'.
Re: stty: standard input: Invalid argument
by PreferredUserName (Pilgrim) on Mar 06, 2006 at 14:32 UTC
    That message is coming from an "stty" command in your .bashrc (or whatever) on mybox. Change this:
    stty what ever ...
    to this:
    if [ -t 0 ]; then # only run if stdin is a terminal stty what ever ... fi
    , and the problem will go away.
      That message is coming from an "stty" command in your .bashrc (or whatever) on mybox.
      Ok I was afraid you'd say that. /etc/bashrc already has the terminal check in it. And removing the stty command doesn't help either.

      There are the following files on the system

    • /etc/bashrc
    • /etc/profile (just noticed this one)
    • /home/username/.bashrc
    • /home/username/.bash_profile

      .bash_profile looks for .bashrc and then runs it. It also sets a couple of var including PATH and EDITOR and exports them.
      .bashrc only looks for /etc/bashrc and then runs it.
      /etc/bashrc has the stty commands but they only run if it is a terminal.
      /etc/profile just sets some vars and runs stuff in
      /etc/profile.d (all of which just set more vars)

      There does not appear to be any other bash startup files used and only /etc/bashrc has an stty command.

      So I'm still perplexed. It sounds like an stty command is still being executed eventhough it shouldn't be. I'm not even sure where to look for it.

        It says right in the error message that it's stty running, so that's definitely what's going on.

        As for what file is running it, just put an "echo TOP", "echo MIDDLE", and "echo BOTTOM" in the top, middle and bottom of your /etc/profile or whatever, and in whatever files he might call or source.

        Move those echoes around to search for the stty in a binary fashion.

Re: stty: standard input: Invalid argument
by Tanktalus (Canon) on Mar 06, 2006 at 14:34 UTC

    First thought is that sudo is looking for a password, which, by default, it gets from the terminal rather than stdin. Adding "-S" may help - but I would expect in this case that sudo would be failing for lack of password.

Re: stty: standard input: Invalid argument
by glasswalk3r (Friar) on Mar 06, 2006 at 14:41 UTC

    Why don't you try to use the Perl module for Sudo integration?

    At least you would avoid the system call (and probably) the problem with stty (but I'm not sure about that).

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill