I use the following script that I generated with autoexpect. When used on command line command sudo surfshark-vpn multi gives a list of about 15 lines and then asks for a final input by the user in the form of a number.
However, when using the expect script on boot those 15 lines become one line each with asking for Enter after each line.
I wonder why this happens. Somehow the command seems to think the shell has just one line.
$ cat startsurfshark.sh
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Sat Dec 12 15:36:12 2020
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
log_file /home/USER/startshark.log
spawn $env(SHELL)
match_max 100000
send -- "sudo surfshark-vpn multi\r"
expect -exact "\[sudo\] Passwort for USER: "
send -- "PASSWORD"
expect -exact "press enter for next page"
send -- "\r"
expect -exact "press enter for next page"
send -- "\r"
expect -exact "press enter for next page"
send -- "\r"
expect -exact "press enter for next page"
send -- "\r"
# ... in here should be a lot more
# ... it then should continou like this
expect -exact "Enter a number to select the location\r"
send -- "2\r"
expect -exact "\r
Enter a number to select the VPN connection type. For default UDP, press ENTER\r
0 TCP\r
1 UDP\r
1 selected\r
"
send -- "\r"
expect -exact "\r
Checking for connection status...\r"
sleep 15
send -- "exit"
Note that I added several lines in the following form manually. That's how I found out about the weird behaviour:
expect -exact "press enter for next page"
send -- "\r"
Note also, that this script would work fine with attack instead of multi because the other command will not print a list that tries to stay on the monitor for the user to watch even if it is too large for the monitor size.
The output of my logfile is:
$ cat ../startshark.log
spawn /bin/bash
sudo surfshark-vpn multi
~ - 21:19:10 - ben - [email protected] Mo Dez 14
$ sudo surfshark-vpn multi
[sudo] Passwort für ben:
press enter for next page
0 France Paris
press enter for next page
1 Germany Frankfurt am Main
press enter for next page
2 Hong Kong Hong Kong
press enter for next page
3 India Chennai
When running the script from a terminal manually (not on boot) it will display the list as follows:
0 France Paris
1 Germany Frankfurt am Main
2 Hong Kong Hong Kong
3 India Chennai
4 Netherlands Amsterdam
5 Netherlands Amsterdam
6 Portugal Loule
7 Singapore Singapore
8 Sweden Stockholm
9 United Kingdom Manchester
10 United Kingdom London
11 United States San Francisco
12 United States Dallas
13 United States New York
Enter a number to select the location
I could also use a form of a while loop to press enter until the list ends. How would I do that?