Edit approach to connect vm #8
This file contains hidden or 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
| # .github/workflows/vm-access.yml | ||
| name: Test Pipeline | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| wget_url: | ||
| description: 'URL to download with wget' | ||
| required: true | ||
| default: 'https://httpbin.org/file.zip' | ||
| jobs: | ||
| access-to-virtual-machine: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Install tools | ||
| run: sudo apt-get update && sudo apt-get install -y expect | ||
| - name: Access to virtual machine | ||
| env: | ||
| SERVER1_HOST: ${{ secrets.SERVER1_HOST }} | ||
| SERVER1_USER: ${{ secrets.SERVER1_USER }} | ||
| SERVER1_PASS: ${{ secrets.SERVER1_PASS }} | ||
| SERVER2_HOST: ${{ secrets.SERVER2_HOST }} | ||
| SERVER2_USER: ${{ secrets.SERVER2_USER }} | ||
| SERVER2_PASS: ${{ secrets.SERVER2_PASS }} | ||
| WGET_URL: ${{ github.event.inputs.wget_url || 'https://httpbin.org/json' }} | ||
| run: | | ||
| # Use expect to handle SSH password prompts | ||
| expect << 'EOF' | ||
| set timeout 30 | ||
| # Connect to first server | ||
| spawn ssh -o StrictHostKeyChecking=no $env(SERVER1_USER)@$env(SERVER1_HOST) | ||
| expect { | ||
| "password:" { | ||
| send "$env(SERVER1_PASS)\r" | ||
| exp_continue | ||
| } | ||
| "$ " { | ||
| # Connected to Server1, now connect to Server2 | ||
| send "ssh -o StrictHostKeyChecking=no $env(SERVER2_USER)@$env(SERVER2_HOST)\r" | ||
| expect { | ||
| "password:" { | ||
| send "$env(SERVER2_PASS)\r" | ||
| exp_continue | ||
| } | ||
| "$ " { | ||
| # Connected to Server2, execute commands | ||
| send "echo 'Connected to Server2' && hostname\r" | ||
| expect "$ " | ||
| send "alias\r" | ||
| expect "$ " | ||
| # Check if vocms0500 command exists, if it's a custom command | ||
| send "which vocms0500 || echo 'vocms0500 command not found'\r" | ||
| expect "$ " | ||
| # Use ls -l instead of ll for better compatibility | ||
| send "ll -l\r" | ||
| expect "$ " | ||
| # send "exit\r" | ||
| expect eof | ||
| } | ||
| timeout { | ||
| puts "Timeout connecting to Server2" | ||
| exit 1 | ||
| } | ||
| } | ||
| } | ||
| timeout { | ||
| puts "Timeout connecting to Server1" | ||
| exit 1 | ||
| } | ||
| } | ||
| EOF | ||