帮我开发一个.sh脚本来启动一个简单的任务

帮我开发一个.sh脚本来启动一个简单的任务

我想要通过 AtlasVPN 自动连接到服务器。

@user: $ atlasvpn connect
1 - Standard
2 - Streaming
3 - SafeSwap
4 - MultiHop
*(IT IS NOT ANOTHER LINE)* Enter a number corresponding to the desired category: 1
1 - Netherlands - Amsterdam
2 - United States - New York
3 - Hong Kong - Hong Kong
4 - United States - Dallas
5 - United States - Los Angeles
6 - Singapore - Singapore
7 - Finland - Helsinki
8 - Norway - Oslo
9 - New Zealand - Auckland
10 - Argentina - Buenos Aires
11 - Hungary - Budapest
12 - Denmark - Copenhagen
13 - Germany - Frankfurt
14 - Bulgaria - Sofia
15 - Sweden - Stockholm
16 - United States - New Jersey
17 - Netherlands - Amsterdam
18 - UAE - Dubai
19 - Serbia - Belgrade
20 - Japan - Tokyo
21 - United Kingdom - London
22 - United Kingdom - Manchester
23 - France - Paris
24 - Poland - Warsaw
25 - Latvia - Riga
26 - Ireland - Dublin
27 - Estonia - Tallinn
28 - Czech Republic - Prague
29 - United States - Las Vegas
30 - Slovakia - Bratislava
31 - Austria - Vienna
32 - United Kingdom - London
33 - Italy - Milan
34 - Spain - Madrid
35 - Canada - Montreal
36 - Turkey - Istanbul
37 - Brazil - Sao Paulo
38 - United States - Miami
39 - Mexico - Mexico City
40 - South Africa - Johannesburg
41 - United States - Phoenix
42 - Israel - Tel Aviv
43 - Chile - Santiago
44 - Thailand - Bangkok
45 - Belgium - Brussels
46 - Albania - Tirana
47 - Taiwan - Taipei
48 - Romania - Bucharest
49 - Switzerland - Zürich
50 - Portugal - Lisbon
51 - Australia - Sydney
*(IT IS NOT ANOTHER LINE)* Enter a number corresponding to the desired server: 38
You have successfully connected to United States - Miami.
@user:
  1. 这种类型的代码不起作用:
#!/bin/bash
atlasvpn connect
1
38

因为“输入与所需类别对应的数字:”和“输入与所需服务器对应的数字:”在同一个命令行中。

在此处输入图片描述

答案1

我尝试过这样的:

#/bin/env expect

spawn atlasvpn connect
expect {
    "Enter a number corresponding to the desired category:\r" {
        send "1\r"
        expect {
            "Enter a number corresponding to the desired server:\r" {
                send "10\r"
                interact
            }
        }
    }
}

但它不起作用。它请求第一个值,然后超时。

相关内容