- 實(shí)現(xiàn)shell腳本切換用戶并執(zhí)行后續(xù)操作泻仙,需要使用expect腳本(或shell調(diào)用expect),如下為一個(gè)簡(jiǎn)單的更新代碼的demo
#! /usr/bin/expect
spawn su - 要切換的賬戶
expect "Pas"
send "您的賬戶密碼\r"
expect "#"
send "whoami\r"
expect "賬戶"
send "cd /u/*/www/*\r"
send "echo 更新代碼中\(zhòng)r"
send "git pull origin dev\r"
send "echo 代碼更新完畢\r"
send "exit\r"
expect eof