ssh-executed script does not terminate when ssh session killed
I have a couple of programs which I execute on a remote host something like this:
Code:
ssh user@remotehost /path/to/command What's weird is that Perl programs terminate ok - it's only my shell scripts which don't die. The code in the shell script is something like this: Code:
#!/bin/bash I tried explicitly trapping various signals and using them to kill the script: Code:
trap exit SIGHUP SIGQUIT SIGTERM I get the same problem using plink (another ssh implementation - part of the Putty suite). I tried various command line options to plink and ssh (disabling allocation of pty etc), but without success. Anyone have any ideas? |
Try the '-t option on ssh:
Code:
ssh -t user@remotehost /path/to/command |
macemoneta, thanks - that works with openssh's ssh client. I just need to work out how to do the same thing with plink now... :-)
|
Turns out the same option with plink works too... I was sure I had tried this option, but apparently not.
So am I right in saying that because -t is used to force allocation of a pty, when the ssh session disconnects, this triggers a SIGHUP getting sent to my script, whose default action for this signal is to exit. Thanks again macemoneta. |
Without the pseudo-tty, I'm pretty sure the signal is discarded.
|
While the -t option solves the problem described above, it introduces a new one, and I'm struggling to understand why...
It seems that when -t is used, the remote command executes with a very naked environment, where as the exact same command executed without the -t option runs in a more fully configured environment. I assume the difference is that without -t, sshd is executing my command in a login shell, and with -t it is not. My question is why? and can I gave both a pty allocated, and a normal environment? |
Unless the shell initialization on the target system is looking for a pseudo-terminal, the environment should be the same when a command is specified. See the 'ENVIRONMENT' section of the ssh man page for setting environment variables.
|
All times are GMT -5. The time now is 01:10 PM. |