我有下面的shell
脚本,在其中我登录到特定的计算机,现在我必须在登录后执行一个命令,该命令将启动/停止/特定进程的状态。
#!/usr/bin/expect -f
spawn ssh root@hostname
expect "Password:"
send "password123\r"
interact # here it is successfully login into machine,
sleep 2
/sbin/service heartbeat status # I want to execute this command
我该怎么办?
您可以使用
ssh user@hostname "command"
这将打开ssh连接并运行命令。如有必要,将提示您输入密码。
如果要自动执行此操作(不想每次都输入密码),则应使用ssh-pub-key启用登录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句