扫码关注官方订阅号
利用expect登录root账户,结果shell也不能继续执行了
#!/bin/sh expect -c " spawn su root expect \"Password:\" send \"*******\r\" interact " 其他shell代码...
其他shell代码...这里不能执行
学习是最好的投资!
其他shell 可以使用在expect中send发送 send \"echo 123;\r\"
我是这么做的,先登陆远程服务器,然后执行删除和重命名操作。
#!/usr/bin/expect -f set timeout 600 spawn ssh root@xx.xx.xx.xx expect "*" send "cd /usr/share/nginx/html\r" send "rm -rf tkb\r" send "mv site tkb\r" interact
切换用户后环境变量已经变了,之前用户的命令是不会生效的,建议使用su -root -c '命令集..'来执行
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
其他shell 可以使用在expect中send发送 send \"echo 123;\r\"
我是这么做的,先登陆远程服务器,然后执行删除和重命名操作。
切换用户后环境变量已经变了,之前用户的命令是不会生效的,建议使用su -root -c '命令集..'来执行