Need Bash script help

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 07-09-2018
Need Bash script help

I have a bash script that does a few things for me. I am setting up a method of using passwordless ssh to move files between a server and several systems. My issue is that I want to use a bash script to automate the keygen and the initial setup. Here is my script
Code:
#!/bin/bash
#!/usr/bin/expect -f

#=====setup ssh to the backup server====

echo "Follow along with the enter key for the next few questions."
echo "We are setting up the SSH connections to the cloud server."
ssh-keygen
spawn ssh-copy-id  user@10.10.10.10
expect "password:"
sleep 1
send -- "password\r"
sleep 3
send -- "exit\r"
spawn ssh user@10.10.10.10
sleep 10
send -- "exit\r"
expect eof

When I run this script I get no interaction and back to a bash prompt. Running th ecommands individually the ssh key is copied and I can ssh into the server with no issues. What am I missing?

Thanks
# 2  
Old 07-09-2018
To me that seems to be a clutter of bash / OS and expect commands, run by /bin/bash through shebang, but missing THE expect itself (that second "shebang" being pointless). No surprise it doesn't do anything sensible.
# 3  
Old 12-05-2018
SSH keys
First of all, the best solution for you would be to create new ssh keypair and use this key to login to all your servers (or some, based on preferences). If you don't know how, you can find it many times here on stackexchange, but shortcut:

Code:
ssh-keygen; ssh-copy-id your-host

Basically you should set passphrase for your key, so you will log in only once with the one password.

SSH pass
But if you really insist on using your passwords from files, you can do it quite simply as described in comments:

Code:
sshpass -f /path/to/myfile ssh user@localhost

But note that this is not really preferred method of using ssh with passwords stored in plaintext.

Expect
You can do the same thing using expect script like this:

Code:
#!/usr/local/bin/expect
spawn  ssh user@yourserver.com
expect "password:"
send "your_password\n";
interact

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to block first bash script until second bash script script launches web server/site? siegfried Shell Programming and Scripting 3 12-11-2018 08:28 AM
Different behavior between bash shell and bash script for cmd da1 Shell Programming and Scripting 5 09-20-2018 07:41 AM
Make a password protected bash script resist/refuse “bash -x” when the password is given frad Shell Programming and Scripting 7 12-09-2013 01:36 PM
Call a Perl script within a bash script and store the ouput in a .txt file mecaka Shell Programming and Scripting 6 11-22-2013 06:07 PM
Expect script called in loop from Bash Script cbo0485 Shell Programming and Scripting 0 05-03-2013 09:32 AM
Bash shell script to check if script itself is running hedkandi Shell Programming and Scripting 8 11-05-2012 01:48 AM
Im new to bash scriping and i found this expression on a bash script what does this mean. kevin298 UNIX for Dummies Questions & Answers 1 10-26-2012 08:04 PM
CGI Perl script to execute bash script- unable to create folder rakeshkumar Programming 0 07-19-2012 04:10 AM
Need bash script to ping the servers and rename the output file each time the script is ran madhudeva Shell Programming and Scripting 4 07-13-2012 05:24 AM
Calling a Perl script in a Bash script -Odd Situation leepet01 Shell Programming and Scripting 5 09-15-2011 05:56 PM
Run bash script within a bash script NBurkhard Shell Programming and Scripting 1 03-18-2011 10:37 AM
Bash Script: modify bash LibRid Shell Programming and Scripting 9 10-25-2010 07:17 PM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 04:17 AM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 01:25 PM
Why generate "ash and bash" different output for same bash script? s. murat Shell Programming and Scripting 0 05-26-2008 08:19 AM