ssh redirection

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
OpenSSH_3.0.2p1, SSH protocols 1.5/2.0, OpenSSL 0x0090603f
Running on AIX 4.3

A script that we've converted to run a ssh command instead of rsh (due
to requirements of a client) is behaving strangely with regards to the
redirection. When the script is run from the command line (and say the
ssh command is ssh -l remotelogin remoteserver command > ssh.log 2>1&)
then this works fine. The results of the command are piped to the log
file fine.

However, the script is actually called from program running on the
server and for some reason, the log file changes to zero bytes (so the
script is trying to do something) but there is nothing else in the
file. When we were using rsh, it worked perfectly and we got results in
the log file.

Is there a specific reason why this would not work? Oy sysadmin thinks
it could be to not having a tty for when the script is called.


Re: ssh redirection wrote:
Quoted text here. Click to load it

It sounds like the presence of a pty makes a difference. Take a look at the
"-T" and "-t" options.

Re: ssh redirection

No luck with that.

-t gives the error : "Pseudo-terminal will not be allocated because
stdin is not a terminal."
-T sporadically gave some output sometimes, nothing other times.


Re: ssh redirection

Quoted text here. Click to load it

Please be more specific -- i.e., include the script you're talking about
(or the salient parts of it if it's large), and the exactly ssh command

  Richard Silverman

Re: ssh redirection

The script is being called by a running program. Basically the script
has the ssh command:

ssh -l remotelogin remoteserver "command" > result.log 2>&1

The results of the command should pipe to the result.log file but when
called from the program the log file only gets created with zero bytes.
Note that the command is actually running ok. It's the output in the
log file that we're interested in since it verifies the command ran ok.

To duplicate the problem the sysadmin has the same command in a cron

08 21 * * 1,2,3,4,5 . /etc/company_profile; /user/bin/sshtest.ksh

with sshtest.ksh holding:

ssh -l remotelogin remoteserver "command" > result.log 2>&1

Again, the resulting file was 0 bytes.

Our sysadmin reckons the issue is to do with the script being called
not having a tty assigned to it.

Re: ssh redirection

Nomen Nescio wrote:
Quoted text here. Click to load it
   Try first removing the "2>&1" and see what happen
   Next, replace "2>&1 with "> result-err.log"

   Or, I recommend the good approach (append):
    ssh -n -l remotelogin remoteserver "command" >> result.log 2>&1

   That way you can see output for more than one run and even spot when
   bad behavior in running your remote script.

Quoted text here. Click to load it

kind regards,

Site Timeline