Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remote SSH Commands
#1

I am trying to remotely call a script file via ssh.

 

the server has a shell that is a custom program, lets call it shelly. There is also a script file on the server that needs to run when in shelly.

 

 

i can run the following after i ssh into the box, as root.

 

 



Code:
exec /usr/local/bin/shelly < /my_folder/custom_script




 

that works fine.

 

I need to be able to embed this in ssh. I have done so like this. I have shared keys so no password needed, and it works.

 

 



Code:
ssh user@server "exec /usr/local/bin/shelly < /my_folder/custom_script"




 

when i run this ssh command from my remote machine the commands are not executed from the script. So i run ssh in debug mode, and after a successful authentication i get a line that says:

 



Code:
Ssh2channelSession/SSHCHSESSION.C : bad data




 

and the connection begins to quit/close.

 

 

I don't understand what "Bad Data" error means, and i do not have this SSHCHSESSION.C file on my server.

 

Is Bad Data mean there is something wrong with the command? or is it a permissions problem on the server?

 

 

Any Ideas?

Reply
#2

Quote:i can run the following after i ssh into the box, as root. 

 



Code:
exec /usr/local/bin/shelly < /my_folder/custom_script

<div>


 

that works fine.

 

I need to be able to embed this in ssh. I have done so like this. I have shared keys so no password needed, and it works.

 

 



Code:
ssh user@server "exec /usr/local/bin/shelly < /my_folder/custom_script"




 

when i run this ssh command from my remote machine the commands are not executed from the script. So i run ssh in debug mode, and after a successful authentication i get a line that says:

 



Code:
Ssh2channelSession/SSHCHSESSION.C : bad data




 

and the connection begins to quit/close.

</div>
 

I'm not sure whether this is relevant, or will fix it, but is there a specific need to use 'exec' to invoke shelly when you're running the command as a direct argument to SSH? I have tested with other programs (obviously not with your shelly), and if you include a command as an argument to SSH, that command will run and then the connection will be closed once the process exits anyway, mimicking the behaviour of what 'exec' would do when you are interactively logged in. I don't particularly see why 'exec' would cause an issue, but if it's not strictly necessary, perhaps excluding it would eliminate it as the issue.

 

 

Quote:I don't understand what "Bad Data" error means, and i do not have this SSHCHSESSION.C file on my server. 

Is Bad Data mean there is something wrong with the command? or is it a permissions problem on the server?

 

 

Any Ideas?
 

 

The SSHCHSESSION.C file isn't on your server (and likely isn't meant to be, unless you grabbed the SSH source code), but it is a reference telling you where in the source code this error is happening. For what it's worth, I found what appears to be this source file here. The error message appears to be at ssh_channel_session_request_pty.

 

I had difficulty reproducing the issue myself, but obviously I don't have your shelly application. That might suggest that it is shelly which is causing the problem here -- perhaps it doesn't like operating outside of an interactive session for some reason.

Reply
#3

Just another note: you mentioned the script runs fine when you ssh in and run it as root, but what happens when you ssh in and run it as "user"..? Your last command suggests you're not running it as the root user, which could then have a different environment.

 

Note also that scripts should have a context (#!/bin/sh) as the first line, as well as setting any environment variables - this is usually a symptom of scripts that run from an interactive shell (login session) then fail to run when automated, since the scripts rely on something specified in a profile file that is parsed during login but not when automating.

Reply
#4

Quote:Note also that scripts should have a context (#!/bin/sh)...
 

So i tried adding the #!/bin/shelly and that seems to correctly bring up the shell i want, however all the commands after this line do not seem to run in the shelly, they are executed after shelly closes.

 

Am i missing some command that keeps the #!/bin/sh open for me to feed it commands that i want?

 

 

right now my script is basically like this:

#!/bin/shelly

enable

 

 

But instead of enable running in the shelly it runs in regular linux shell.

 

thanks for the help

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)