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.
以下是我目前的.bat内容。我在窗口cmd上运行它。它会连接到远程linux服务器并提示我密码。但是在我输入密码并登录为remotehost后,linux服务器将不会运行我的ls命令。请帮忙。
@echo off
ssh remotehost@10.1.1.10
ls
2 个解决方案
#1
1
You really should do man ssh
as this is explained there (and you could also make an internet search to get an answer).
你真的应该做man ssh,因为这里有解释(你也可以进行互联网搜索以获得答案)。
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'
.
但是,无论如何要回答你的问题:你应该把你想要在远程机器上运行的所有命令与实际的ssh命令放在同一行,例如运行目录列表和grep包含“foo”的所有文件,执行:ssh < user> @
#2
0
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:
我暗示可以在我对@Sami Laine的评论中将代码放在批处理文件中。这就是它的样子:
@echo off
setlocal
:: Run the end of this file in remote computer
more +8 %0 | plink user@remote.compu.ter "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.
我正在使用plink,因为我已安装但它应该适用于大多数ssh风格。也适用于ksh和zsh。也许还有tcsh csh等。这有时候很有用。相同的技术可以用于很多事情。小心它必须在右边的+8偏移值。
#1
1
You really should do man ssh
as this is explained there (and you could also make an internet search to get an answer).
你真的应该做man ssh,因为这里有解释(你也可以进行互联网搜索以获得答案)。
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'
.
但是,无论如何要回答你的问题:你应该把你想要在远程机器上运行的所有命令与实际的ssh命令放在同一行,例如运行目录列表和grep包含“foo”的所有文件,执行:ssh < user> @
#2
0
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:
我暗示可以在我对@Sami Laine的评论中将代码放在批处理文件中。这就是它的样子:
@echo off
setlocal
:: Run the end of this file in remote computer
more +8 %0 | plink user@remote.compu.ter "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.
我正在使用plink,因为我已安装但它应该适用于大多数ssh风格。也适用于ksh和zsh。也许还有tcsh csh等。这有时候很有用。相同的技术可以用于很多事情。小心它必须在右边的+8偏移值。