Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

Prevent expect from hanging when running through ssh

$
0
0

Based on another post's answer, i managed to make expect automate vncserver through ssh (optionally on a chroot in this case), like so:

ssh user@ip "rm ~/.vnc/passwd"echo -n "`PASS_VNC`" | ssh user@ip "cat > PASS_VNC.file"ssh user@ip << 'EOF'export TERM=xtermchroot /targetdirPWD="$( cat PASS_VNC.file )"/usr/bin/expect <<EODset timeout -1spawn screen bashsend -- "/usr/bin/vncserver -geometry 1366x768 :1\r"expect "Password:"send -- "$PWD\r"expect "Verify:"send -- "$PWD\r"expect "Would you like to enter a view-only password"send -- "n\r"expect eofEODEOF

That work, both for setting up the password (generated by another function called PASS_VNC, which i save in a file on the remote machine) + launching vncserver successfully...problem is, it hang (when the expect script finish), and I'm always obliged to use Ctrl+Cmanually.

I tried everything i could think of, whether it's using exit in the expect script, close (part of expect), sleep, send -- \x03 (for sending Ctrl+C), etc.

I'm unsure how to prevent the hanging. How could i do this in this specific instance? I'm guessing the hanging might come from either expect eof or set timeout -1, but if those are removed, then the script wouldn't work right, at least in my own testing.

Using -t with ssh doesn't help much if at all (same result).

PS: I prefer to not send a script over scp and prefer this method of using ssh with an heredoc if possible.


Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>