#!/usr/bin/expect
## Access CLI
set serverIP [lindex $argv 0]
set loginUser [lindex $argv 1]
set loginPassword [lindex $argv 2]
set rootPassword [lindex $argv 3]
## Expect Parameters
set timeout 1
spawn ssh -l $loginUser $serverIP
expect_after eof {exit 0}
##interact with SSH
expect "yes/no" { send "yes\r" }
set timeout 2
expect "password:" { send "$loginPassword\r" }
puts "\n## Starting Check su Script... ##\n"
## $ 프롬프트를 기다리고 su 명령어 시도
expect "$"
send "LANG=c\r"
expect "$"
send "su - root\r"
expect "Password:" { send "$rootPassword\r" }
expect "root" { puts "\n\nSUCCESS $serverIP\n\r"; exit } \
timeout { puts "\n\nFAILED $serverIP\n\r"; exit }