4

I am attempting to execute a binary on my ssh server as soon as I log in. However I may want to push the update of my binary with a single ssh login and execute aswell. My current process for do this is

cat exec | ssh user@host 'cat - > exec; chmod +x exec; ./exec'

This does not work as when I hit the accutal execution it appears to just freeze. I get no response from the server after this. The strange thing is once I have uploaded the file I can simply execute

ssh user@host './exec'

and the file is executed just fine. I know it is reaching the execution process of the binary and the chmod is correctly setting the executable bit of the file it just will not execute in a single command. Does anyone have any suggestions.

2 Answers 2

2

Use tar instead of cat, and tar preserves mode as well if exec has x bit on.

tar cf - ./exec | ssh user@server 'tar xf -; ./exec'

7
  • No it still doesn't work I have the same problem May 2, 2012 at 3:48
  • Add a v before f, so -cvf and -xvf as tar options, then verify that ./exec on remote server is executable and same file length by ls -l ./exec, what do you see? I have used the method many times without issues. If still not work possibly your binary is expecting something unexpected.
    – johnshen64
    May 2, 2012 at 3:54
  • No verbose is verifying the file exists after the transfer. LS confirms that the proper permissions are set as well. Executing ssh user@host './exec' still results in the expected results after the initial transfer aswell. May 2, 2012 at 3:59
  • Can you test the process with a system binary such as /bin/ls copied to your own home? That will rule out differences in our system setups.
    – johnshen64
    May 2, 2012 at 4:19
  • It works when I execute /bin/ls. I am at a loss why it won't work for my own binary on the first try, but still work on the second. May 2, 2012 at 4:31
1

My guess would be that your binary is stumbling into the ssh escape sequence. ssh isn't guaranteed to be binary transparent, but you could see if adding '-e none' to your ssh command will work.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .