LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-09-2012, 10:08 AM   #1
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 13

Rep: Reputation: Disabled
Unhappy 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\" 
")

Last edited by noguru; 10-21-2012 at 04:56 PM. Reason: adding script interpreter spec (bash)
 
Old 10-09-2012, 06:51 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,481
Blog Entries: 6

Rep: Reputation: Disabled
[code][/code] tags Please.
Thank you.
 
1 members found this post helpful.
Old 10-10-2012, 06:38 AM   #3
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
[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.
 
Old 10-10-2012, 12:35 PM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,481
Blog Entries: 6

Rep: Reputation: Disabled
Thank you very much.
 
Old 11-01-2012, 08:52 AM   #5
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by noguru View Post
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!
 
  


Reply

Tags
bash, expect


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash: concatenating the output of multiple commands without using temp files twoprop Linux - Software 3 03-16-2012 12:22 AM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
[SOLVED] expect help (multiple commands in argument) vikas027 Programming 10 03-17-2010 01:19 AM
Expect cannot find commands feilb Linux From Scratch 2 07-22-2008 02:00 PM
multiple commands assigned to bash variable itzamecwp Linux - Newbie 3 02-14-2007 06:40 AM


All times are GMT -5. The time now is 07:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration