linux下使用shell脚本切换到root用户并执行脚本

需要安装expect

yum install expect -y

#!/usr/bin/expect
spawn su root
expect "Password:"
send "这里写root用户的密码\r"
send "cd /home/wwwroot/script/\r"
send "./cache-face.sh\r"

expect eof
exit 

 

你可能感兴趣的:(linux)