33name : Test Pipeline
44
55on :
6- # push:
7- # branches: [ "Pipeline" ]
86 workflow_dispatch :
97 inputs :
10- message :
8+ wget_url :
119 description : ' URL to download with wget'
1210 required : true
13- default : ' https://example.com /file.zip'
11+ default : ' https://httpbin.org /file.zip'
1412
1513jobs :
1614 access-to-virtual-machine :
1715 runs-on : ubuntu-latest
1816
19-
2017 steps :
2118 - name : Install tools
2219 run : sudo apt-get update && sudo apt-get install -y expect
@@ -31,22 +28,53 @@ jobs:
3128 SERVER2_PASS : ${{ secrets.SERVER2_PASS }}
3229 WGET_URL : ${{ github.event.inputs.wget_url || 'https://httpbin.org/json' }}
3330 run : |
34- # Method 1: Use expect to handle SSH password prompts
35- expect << EOF
36- spawn ssh -o StrictHostKeyChecking=no $SERVER1_USER@$SERVER1_HOST
37- expect "password:"
38- send "$SERVER1_PASS\r"
39- expect "$ "
40- send "ssh -o StrictHostKeyChecking=no $SERVER2_USER@$SERVER2_HOST\r"
41- expect "password:"
42- send "$SERVER2_PASS\r"
43- expect "$ "
44- send "echo 'Connected to Server2' && hostname\r"
45- expect "$ "
46- send "alias\r"
47- expect "$ "
48- send "vocms0500\r"
49- expect "$ "
50- send "ll\r"
51- expect "$ "
52- EOF
31+ # Use expect to handle SSH password prompts
32+ expect << 'EOF'
33+ set timeout 30
34+
35+ # Connect to first server
36+ spawn ssh -o StrictHostKeyChecking=no $env(SERVER1_USER)@$env(SERVER1_HOST)
37+ expect {
38+ "password:" {
39+ send "$env(SERVER1_PASS)\r"
40+ exp_continue
41+ }
42+ "$ " {
43+ # Connected to Server1, now connect to Server2
44+ send "ssh -o StrictHostKeyChecking=no $env(SERVER2_USER)@$env(SERVER2_HOST)\r"
45+ expect {
46+ "password:" {
47+ send "$env(SERVER2_PASS)\r"
48+ exp_continue
49+ }
50+ "$ " {
51+ # Connected to Server2, execute commands
52+ send "echo 'Connected to Server2' && hostname\r"
53+ expect "$ "
54+
55+ send "alias\r"
56+ expect "$ "
57+
58+ # Check if vocms0500 command exists, if it's a custom command
59+ send "which vocms0500 || echo 'vocms0500 command not found'\r"
60+ expect "$ "
61+
62+ # Use ls -l instead of ll for better compatibility
63+ send "ll -l\r"
64+ expect "$ "
65+
66+ # send "exit\r"
67+ expect eof
68+ }
69+ timeout {
70+ puts "Timeout connecting to Server2"
71+ exit 1
72+ }
73+ }
74+ }
75+ timeout {
76+ puts "Timeout connecting to Server1"
77+ exit 1
78+ }
79+ }
80+ EOF
0 commit comments