Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 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'

share|improve this answer
    
No it still doesn't work I have the same problem –  Blackninja543 May 2 '12 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 '12 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. –  Blackninja543 May 2 '12 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 '12 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. –  Blackninja543 May 2 '12 at 4:31

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.