0

I want to automate my support work. I want to make a script that will connect to a server and do some CRUD operation on the server and again return to local machine. I don't want to upload the script.Till now I have made a script that will help to connect to the server but i am not able to do any any other operations through. Is it possible to run a local script on the remote server?

My script:

!/usr/bin/expect 
  set ip neviss
  set user user 
  set password 1234 
  spawn ssh "$user\@$ip" 
  expect "Password:" 
  send "$password\r"; 
  interact ( after this line any command is not getting executed) 
  ls -lrt
4

3 回答 3

2

你可以这样做:

ssh user@remote-ssh-server "commands of script" 

如果将脚本保存到文件中,则可以这样做:

ssh user@remote-ssh-server << End
paste the script here
End

这里有一些细节。

  1. 登录"ssh your_user@ssh_server ls /"

此命令将登录,列出根目录,并关闭连接。

  1. 第一遍成功后,尝试用您的脚本替换“ls /”。

  2. 第二步成功后,启动 ssh 代理。

在完成第一步之前不要进入第 2 步。

使用像这样的 ssh 教程——这将对你有所帮助

http://support.suso.com/supki/SSH_Tutorial_for_Linux

于 2012-11-23T11:19:51.370 回答
0
ssh user@server bash < /path/to/local/script.sh
于 2012-11-23T11:26:15.483 回答
0

你的脚本结构应该是:

  1. 通过 SSH 连接。
  2. CRUD 操作
  3. 退出 SSH。

具有 CRUD 操作的脚本必须在远程计算机上,因为您无法运行不在您要运行它的机器上的任何脚本。

于 2012-11-23T10:18:17.453 回答