LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   using expect in bash for multiple independent commands (https://www.linuxquestions.org/questions/linux-newbie-8/using-expect-in-bash-for-multiple-independent-commands-4175431340/)

noguru 10-09-2012 10:08 AM

using expect in bash for multiple independent commands
 
I have a bash script which will run multiple commands against 35-50 remote systems. I cannot use RSA keys (yet). ONE of the jobs of the script is to install my public key on these systems (I have the root passwords for all of them).
The script successfully uses expect with ssh to login and create the .ssh directory, but the expect for the next command, scp, does not run at all. I have turned on exp_internal 1 and I get no output from it. It's as if the expect is ignoring the spawn. (The $cpyparms is properly expanded with lvm being expanded too, before the 2nd expect is started)

Here is the relevant portion of my script:
Code:

#!/bin/bash
cmd1="mkdir ~root/.ssh"
lvm="mydomain"
cpyparms="~/.ssh/rootskey.pub root@"${lvm}":~/.ssh"
      echo "creating sshdir on" $id
VAR=$(/usr/local/bin/expect -c "
spawn ssh $user@$lvm $cmd1
expect \"password:\"
send \"secretpass\r\"
expect \"\r\n\"
expect EOF
")
          echo "#---- copying sshkey from myself ----#"
VAR=$(/usr/local/bin/expect -c"
exp_internal 1;
spawn scp $cpyparms
expect \"password:\"
send \"secretpass\r\"
expect \"\r\n\"
")


Habitual 10-09-2012 06:51 PM

[code][/code] tags Please.
Thank you.

noguru 10-10-2012 06:38 AM

Quote:

Originally Posted by Habitual (Post 4801673)
[code][/code] tags Please.
Thank you.

Thanks for the tip. I did not understand that the # icon was for adding those tags. I've done it.

Habitual 10-10-2012 12:35 PM

Thank you very much.

noguru 11-01-2012 08:52 AM

Quote:

Originally Posted by noguru (Post 4801344)
I have a bash script which will run multiple commands against 35-50 remote systems. I cannot use RSA keys (yet). ONE of the jobs of the script is to install my public key on these systems (I have the root passwords for all of them).
The script successfully uses expect with ssh to login and create the .ssh directory, but the expect for the next command, scp, does not run at all. I have turned on exp_internal 1 and I get no output from it. It's as if the expect is ignoring the spawn. (The $cpyparms is properly expanded with lvm being expanded too, before the 2nd expect is started)

Here is the relevant portion of my script:
Code:

#!/bin/bash
cmd1="mkdir ~root/.ssh"
lvm="mydomain"
cpyparms="~/.ssh/rootskey.pub root@"${lvm}":~/.ssh"
      echo "creating sshdir on" $id
VAR=$(/usr/local/bin/expect -c "
spawn ssh $user@$lvm $cmd1
expect \"password:\"
send \"secretpass\r\"
expect \"\r\n\"
expect EOF
")
          echo "#---- copying sshkey from myself ----#"
VAR=$(/usr/local/bin/expect -c"
exp_internal 1;
spawn scp $cpyparms
expect \"password:\"
send \"secretpass\r\"
expect \"\r\n\"
")


This problem still exists. If anyone has a clue as to how I can fix it or how I can debug it, I would appreciate the help!


All times are GMT -5. The time now is 05:13 PM.