Solved Remote execution via Ruby-SSH starts different shell

Hello,

we are using net/ssh in Ruby to execute scripts on a FreeBSD machine, in order to do some checks for Nagios. Actually it is a brand new Pfsense applicance.
The code is roughly the following:
Code:
Net::SSH.start(@host, @user, {:password=>@pass}) do |ssh|
   erg=ssh.exec! "ls -al"
   p erg
end
When we execute this, we get a message, that the parameter "l" in "ls -al" is wrong. This is strange to me, as this works on a normal command line. Passing "ls -a" works however and produces the desired output.
"echo $0" shows not output, so I suspect, there is something wrong with the shell here.

Remotely executing "env" displays the following
Code:
SSH_CLIENT=192.168.12.252 53798 22
LOGNAME=admin
FTP_PASSIVE_MODE=YES
MAIL=/var/mail/admin
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
PWD=/root
TERM=su
USER=admin
HOME=/root
SSH_CONNECTION=192.168.12.252 53798 192.168.12.254 22
SHELL=/etc/rc.initial
BLOCKSIZE=K

We also tried to execute "tcsh -c <command>" but he complains about the "-c" parameter.

So I am confused, which shell is actually run, when remotely executing via ssh. And how I can run an remote command via tcsh?

Any help is appreciated.
 
Connections like this typically use /bin/sh, not tcsh(1). But regardless of the shell, ls(1) is not a shell builtin, so the shell itself is irrelevant.
 
The easiest way to sort this out, in my opinion, is to set up process accounting for the used user account. Take a good look at which commands were really executed, something tells me that's where things probably went wrong.
 
Thanks for the hint. I tried it, but it only showed the command. The parameters are not shown with lastcomm or sa.

So, as I wanted to watch an ipsec tunnel, I made a copy of the ipsec shell script to ipsec2 and added
Code:
echo "ipsec2: $0 $1 $2 $3"
And executed via ssh from the command line of my local machine:
Code:
"
ssh -tq admin@192.168.12.254 "/usr/local/sbin/ipsec2 status 1 2 3 4 5"
and received
Code:
ipsec2: /usr/local/sbin/ipsec2

I should have received
Code:
ipsec2: /usr/local/sbin/ipsec2 status 1 2 3 4 5
So $0 is evaluated, but $1, $2 .. are not there. They seem not to be passed.
 
Back
Top