最近我一直试图让这个脚本工作:
#!/usr/bin/expect -f
set pssword [lrange $argv 0 0]
spawn su - kod -c cd cod4 -c "nohup kill 7938" > /dev/null 2>&1 &
expect "Password:" { send "$pssword\r" }
expect "# " { send "q" }
exit
它应该以名为“kod”的用户身份登录并通过某个 pid 终止进程
这是启动脚本,它工作得很好......
#!/usr/bin/expect -f
set pssword [lrange $argv 0 0]
set port [lrange $argv 1 1]
set mod [lrange $argv 2 2]
set map [lrange $argv 3 3]
set num [lrange $argv 4 4]
set hostname [lrange $argv 5 5]
set rcon [lrange $argv 6 6]
set password [lrange $argv 7 7]
spawn su - kod -c cd cod4 -c "nohup ./cod4_lnxded +set s_num=$num +set net_port $port +set dedicated 2 +set fs_game mods/$mod +set sv_punkbuster 1 +set sv_hostname $hostname +set rcon_password $rcon +set g_password $password +set promod_mode match_mr10 +set g_gametype sd +map $map" > /dev/null 2>&1 &
expect "Password:" { send "$pssword\r" }
expect "# " { send "q" }
exit
请不要告诉我“以 root 身份登录”或“只使用 sudo”,因为事实并非如此......谢谢!