Brandon Simmons
2007-Jul-26 22:30 UTC
BUG?: Assigning a Perl script as user shell + sending commands on ssh connect
Hi, This is sort of a strange issue. But I am experimenting with ways to have a user log in and be presented with a perl script to interact with. When I do either or both of the following: 1) set the user's shell to /usr/bin/myperlscript 2) specify ForceCommand /usr/bin/myperlscript, applied to my user ...I get strange behavior when a command is appended to the client connect command in this way: ssh -l user 192.168.1.2 ls /etc The output from the perl script is not printed immediately but waits for a carriage return from the user before it is printed to the screen> Here is an example using a test perl script: me at computer:~$ ssh -l user 192.168.1.2 /bin/bash user at 192.168.1.2's password: echo "I'm typing this line while the script seems not to be running" here we go! enter something: YOU SAID: echo "I'm typing this line while the script seems not to be running" You can see that what I type is taken as <STDIN> by the script, so I guess the output is stuck in a buffer somewhere. not sure if this is a bug in OpenSSH or a perl oddity. Or maybe I really shouldn't be setting my user's shell to be a script.
Jefferson Ogata
2007-Jul-26 23:47 UTC
BUG?: Assigning a Perl script as user shell + sending commands on ssh connect
On 2007-07-26 22:30, Brandon Simmons wrote:> You can see that what I type is taken as <STDIN> by the script, so I > guess the output is stuck in a buffer somewhere. not sure if this is a > bug in OpenSSH or a perl oddity. Or maybe I really shouldn't be > setting my user's shell to be a script.Have you tried setting autoflush on the output stream from your Perl script? -- Jefferson Ogata <Jefferson.Ogata at noaa.gov> NOAA Computer Incident Response Team (N-CIRT) <ncirt at noaa.gov> "Never try to retrieve anything from a bear."--National Park Service
Darren Tucker
2007-Jul-26 23:56 UTC
BUG?: Assigning a Perl script as user shell + sending commands on ssh connect
On Thu, Jul 26, 2007 at 06:30:03PM -0400, Brandon Simmons wrote:> Hi, > This is sort of a strange issue. But I am experimenting with ways to > have a user log in and be presented with a perl script to interact > with. When I do either or both of the following: > > 1) set the user's shell to /usr/bin/myperlscript > > 2) specify ForceCommand /usr/bin/myperlscript, applied to my user > > ...I get strange behavior when a command is appended to the client > connect command in this way: > > ssh -l user 192.168.1.2 ls /etc > > The output from the perl script is not printed immediately but waits > for a carriage return from the user before it is printed to the > screen> Here is an example using a test perl script:[...]> You can see that what I type is taken as <STDIN> by the script, so I > guess the output is stuck in a buffer somewhere. not sure if this is a > bug in OpenSSH or a perl oddity. Or maybe I really shouldn't be > setting my user's shell to be a script.Try setting stdin/out to unbuffered in your perl script: select STDERR; $| = 1; select STDOUT; $| = 1; -- Darren Tucker (dtucker at zip.com.au) GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69 Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.