Need Bash script help

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
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  
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
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My...... Shell Programming and Scripting
3
Shell Programming and Scripting
Different behavior between bash shell and bash script for cmd
da1
So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s...... Shell Programming and Scripting
5
Shell Programming and Scripting
Im new to bash scriping and i found this expression on a bash script what does this mean.
kevin298
# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was...... UNIX for Dummies Questions & Answers
1
UNIX for Dummies Questions & Answers
how to make your bash script run on a machine with csh and bash
npatwardhan
hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there...... Shell Programming and Scripting
3
Shell Programming and Scripting
passing variable from bash to perl from bash script
arsidh
Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has...... Shell Programming and Scripting
10
Shell Programming and Scripting

Featured Tech Videos