Last active
January 31, 2017 01:36
-
-
Save wcomnisky/4edccd9868c6ccfda1ab70755f8a28a2 to your computer and use it in GitHub Desktop.
Expect script to SSH-access a machine, login to another user, run x11vnc and close the session after close the VNC client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -- | |
# Argument: | |
# argv0 = host | |
# | |
# Usage: | |
# expect.sh ip-or-hostname | |
spawn ssh -o StrictHostKeyChecking=no -p 22 -L 9000:localhost:5900 user@[lindex $argv 0] | |
set timeout 120 | |
expect { | |
timeout { | |
puts "Connection timed out" | |
exit 1 | |
} | |
"yes/no" { | |
send "yes\r" | |
exp_continue | |
} | |
"assword:" { | |
send -- "password-1\r" | |
expect "@hostname:" | |
} | |
} | |
send -- "su another-user\r" | |
expect "Password: " | |
send -- "password-2\r" | |
expect "another-user@hostname:" | |
send -- "DISPLAY=:0 x11vnc\r" | |
set viewerexited "false" | |
while {$viewerexited == "false"} { | |
sleep 1 | |
expect { | |
"viewer exited." { | |
set viewerexited true | |
} | |
} | |
} | |
# Logout from 'user' user | |
send -- "exit\r" | |
expect "exit" | |
# ends SSH session | |
send -- "exit\r" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment