continuous integration - A local run of expect script works fine, but hangs when ran through gitlab CI -
i'm writing expect file connect handle interaction remote device using script looks following, , facing few problems it. mainly, when run script stand-alone or interactively (on runner), works wish, when plug in code testing using gitlab ci on 1 of runners, has following problems:
- the command
spawn /usr/bin/scp $rsafile remote:/var/root/id_rsa.pub
doesn't seem show in ci log (though firstspawn /usr/bin/ssh remote
command shows up) - suspect it's not being called @ all. - the same spawn command persistently gives me following message until script stops executing @ next interact command:
"warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\n"
- interact complains
spawn id exp0 not open
(which assume may because scp command not working properly)
here's code:
spawn /usr/bin/ssh remote expect { -re ".*assword:.*" { exp_send "password\r"; exp_continue } -re ".*sh.*" { exp_send "mount -uw /\r"; exp_send "nvram -somecommand" exp_send "exit\r" } } interact # copy on key set rsafile "/var/root/resources/id_rsa.pub" spawn /usr/bin/scp $rsafile remote:/var/root/id_rsa.pub; expect { # 1&2 added original script debugging purposes -re "^id_rsa.pub.*" { #1: output i'd expect in case of successful scp exp_send "exit\r" } -re ".*assword:.*" { exp_send "password\r"; exp_send "exit\r" } -re "warning:.*warning.*warning.*" { #2: debug expect hanging exp_send "exit\r" } } interact;
here's error msg (expect on debug mode):
spawn /usr/bin/ssh remote parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {24373} gate keeper glob pattern '.*assword:.*' '*assword:*'. activating booster. gate keeper glob pattern '.*sh.*' '*sh*'. activating booster. expect: "" (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=no warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts. expect: "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\n" (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=no root@fe80::cccc:48ff:fe33:3344%en4's password: expect: "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nroot@fe80::cccc:48ff:fe33:3344%en4's password: " (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=yes re=yes expect: set expect_out(0,string) "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nroot@fe80::cccc:48ff:fe33:3344%en4's password: " expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nroot@fe80::cccc:48ff:fe33:3344%en4's password: " send: sending "password\r" { exp6 } expect: continuing expect expect: "" (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=no expect: "\r\n" (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=no expect: "\r\n\u001b[?1034h" (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=no -sh-3.2# expect: "\r\n\u001b[?1034h-sh-3.2# " (spawn_id exp6) match regular expression ".*assword:.*"? gate "*assword:*"? gate=no ".*sh.*"? gate "*sh*"? gate=yes re=yes expect: set expect_out(0,string) "\r\n\u001b[?1034h-sh-3.2# " expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "\r\n\u001b[?1034h-sh-3.2# " send: sending "mount -uw /\r" { exp6 } send: sending "nvram -some-command" { exp6 } send: sending "exit\r" { exp6 } interact: received eof spawn_id exp0 parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {24376} gate keeper glob pattern '^id_rsa.pub.*' 'id_rsa?pub*'. activating booster. gate keeper glob pattern '.*assword:.*' '*assword:*'. activating booster. gate keeper glob pattern 'warning:.*warning.*warning.*' ''. not usable, disabling performance booster. expect: "" (spawn_id exp1) match regular expression "^id_rsa.pub.*"? gate "id_rsa?pub*"? gate=no ".*assword:.*"? gate "*assword:*"? gate=no "warning:.*warning.*warning.*"? (no gate, re only) gate=yes re=no expect: "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\n" (spawn_id exp1) match regular expression "^id_rsa.pub.*"? gate "id_rsa?pub*"? gate=no ".*assword:.*"? gate "*assword:*"? gate=no "warning:.*warning.*warning.*"? (no gate, re only) gate=yes re=no expect: "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\n" (spawn_id exp1) match regular expression "^id_rsa.pub.*"? gate "id_rsa?pub*"? gate=no ".*assword:.*"? gate "*assword:*"? gate=no "warning:.*warning.*warning.*"? (no gate, re only) gate=yes re=no expect: "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\n\r\n\r\n\r\n" (spawn_id exp1) match regular expression "^id_rsa.pub.*"? gate "id_rsa?pub*"? gate=no ".*assword:.*"? gate "*assword:*"? gate=no "warning:.*warning.*warning.*"? (no gate, re only) gate=yes re=yes expect: set expect_out(0,string) "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\n\r\n\r\n\r\n" expect: set expect_out(spawn_id) "exp1" expect: set expect_out(buffer) "warning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\nwarning: permanently added 'fe80::cccc:48ff:fe33:3344%en4' (ecdsa) list of known hosts.\r\n\r\n\r\n\r\n\r\n\r\n" send: sending "exit\r" { exp1 } interact: spawn id exp0 not open while executing "interact" (file "./resources/setup.command" line 44) error: build failed: exit status 1
any appreciated! in advance btw- problem annoying enough me figure out, first post stack overflow. :)
try this:
spawn /usr/bin/ssh remote expect { -re ".*assword:.*" { exp_send "password\r"; exp_continue } -re ".*-sh-.*" { exp_send "mount -uw /; nvram -somecommand; exit\r" exp_continue } eof {} } wait set rsafile "/var/root/resources/id_rsa.pub" spawn /usr/bin/scp $rsafile remote:/var/root/id_rsa.pub; expect { -re ".*assword:.*" { exp_send "password\r"; exp_continue } eof {} } wait
your interact
may fail because @ time spawned process may have exited , cannot interact dead process.
for script, expect eof
have same effect interact
. wait spawned process finish. difference here timing. , expect eof
not generate error when spawned process exits.
Comments
Post a Comment