Reputation: 101
Below is my current .bat content. i run it on window cmd. it will connect to remote linux server and prompt me password. but after i put the password and login as remotehost, linux server wont run my ls command. please help.
@echo off
ssh [email protected]
ls
Upvotes: 2
Views: 3257
Reputation: 4434
I hinted that it is possible to have the code in a batch file in my comment to @Sami Laine. This is what it would look like:
@echo off
setlocal
:: Run the end of this file in remote computer
more +8 %0 | plink [email protected] "tr -d '\r'| bash"
endlocal
exit /b 0
:: remote bash stuff to be bootstrapped
pwd
ls -h
I'm using plink, because that what I have installed but it should work with most flavors of ssh too. Works also with ksh and zsh. Probably also with tcsh csh etc. This can sometimes be useful. Same technique can be used for a lot of things. Be careful with the +8 offset value it has to be on the right line.
Upvotes: 0
Reputation:
You really should do man ssh
as this is explained there (and you could also make an internet search to get an answer).
But, to answer your question anyway: you should put all commands you want to run on the remote machine on the same line with the actual ssh command, for example to run directory listing and grep all files containing "foo", do: ssh <user>@<host> 'ls|grep foo'
.
Upvotes: 1