Expect not working inside my Bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect not working inside my Bash script
# 1  
Old 09-27-2014
Code Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows:

Code:
#!/bin/bash
HOST=$1
/usr/bin/expect -c "
                    spawn ssh -i /root/.ssh/id_rsa root@$HOST  
                    expect -exact "Enter passphrase for key '/root/.ssh/id_rsa': " ;
                    send "PASSPHRASE\n" ; 
                    interact
                   "

Output with error is: Smilie

Code:
spawn ssh -i /root/.ssh/id_rsa root@server.domain.com
couldn't read file "passphrase": no such file or directory

Can you help to correct this? Smilie
# 2  
Old 09-27-2014
What system are you working on?
To me it 'works' as in.... i get spamed, line after line, by 'y' after adding the hosts to known (asked by ssh).

I did change /root to $HOME though...
# 3  
Old 09-27-2014
I am running it in Ubuntu
# 4  
Old 09-27-2014
I get the impression that management crossed their wires somewhere and handed you contradictory requirements, because the utter futility of bruteforcing interactive plaintext passwords into an ssh key is quite glorious.

I would suggest ssh-agent instead. Type the password in securely and once, and your session will remember it for as long as it's open, without embedding the password in a script for everyone to read. Because this is using the system as it's intended to be used, you do not need to install the third-party brute-forcing utility expect to do so.

Or just removing the password from the key.

Last edited by Corona688; 09-27-2014 at 04:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

2. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

3. Shell Programming and Scripting

scp not working in expect script

Hi All, I run the scp command in shell prompt without issue, but when on expect script as below: #!/usr/bin/expect spawn scp /var/spool/sms/failed.tar.gz abc@10.10.12.2:/home/abc expect "abc@10.10.12.2's password: " send "abcfef\r" exit 0 It looks not working at all and the... (3 Replies)
Discussion started by: elingtey
3 Replies

4. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

5. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

6. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

7. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

8. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

9. Shell Programming and Scripting

how to read line inside expect script

hi, i have an existing ftp script that needs to be translated to SFTP so i have to use expect script to automate the login to the remote server. Now im facing with a problem becaise i have at least 50 files to be renamed ont he remote server. It's a hassle to hardcode every single command... (1 Reply)
Discussion started by: The One
1 Replies

10. Shell Programming and Scripting

how to run shell script inside expect script?

I have the code like this : shell script continues ... .... expect -c" spawn telnet $ip expect "login:" send \"$usrname\r\" expect "Password:" send \"$passwd\r\" expect "*\>" send \"$cmdstr\r\" ... (1 Reply)
Discussion started by: robbiezr
1 Replies
Login or Register to Ask a Question