[Solved] Using SSH in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Using SSH in bash script
# 1  
Old 10-19-2011
[Solved] Using SSH in bash script

Hello,

I am writing a script that has to log in to X number of servers over a full C class range.

I am only keyed on a certain number of these servers and this can change from time to time.

The part of my script that deals with this is

Code:
for i in $(cat $server_list); do
       ssh  root@$i "Run commands!"
done

If I connect to a server that I am not keyed on I get a password prompt. Is there a way (return code?) that I can detect this and then move on to the next server? Or does anyone know a way I can add some sort of timeout to the script?

Regards,
Colin

---------- Post updated at 09:39 PM ---------- Previous update was at 03:48 PM ----------

Code:
ssh -o PreferredAuthentications=publickey root@1.2.3.4

if anyone is interested

Last edited by radoulov; 10-19-2011 at 06:06 PM.. Reason: Marked as solved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Grep in bash script

Hi Experts, I'm writing script to find out last files and its modified date - unfortunately am having problem with the below script. Error message: "grep: sales.txt: No such file or directory" #!/bin/bash var=1 var1=`awk '{n++} END {print n}' sales.txt` while ] do prod=$var... (6 Replies)
Discussion started by: parpaa
6 Replies

2. Shell Programming and Scripting

[Solved] Unable to call a python script from bash

Hi, I am trying to run a python script embedded in bash script. But is throwing me an error. Please help. Script: #!/bin/bash nohup /usr/bin/python /opt/web/http.py & Error: /usr/bin/python: can't open file '/opt/web/http.py': No such file or directory Please help me on this. (6 Replies)
Discussion started by: maddy26615
6 Replies

3. Shell Programming and Scripting

Help on an ssh bash script...

Hey Guys, I want to have a bash script on my computer (Mac OS X 10.6.8) that can ssh into my iPod and respring. I know how do this by typing in "ssh root@10.0.1.10" and then typing in the password "alpine". From there i simply type "respring". I want to possibly put this into a shell script so it... (0 Replies)
Discussion started by: jetstream131
0 Replies

4. Shell Programming and Scripting

ssh to run bash script

I want to use ssh to start a bash script that I have uploaded to a webhost. How do I do that from linux? (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

[Solved] Output in bash script not captured in variable

I'm tring to write down a simple script that would execute a command and wait until it returns a specific result. This is what i did: bjobs_out=`bjobs` while ]; do bjobs_out=`bjobs` sleep 6 done It seems to work until the command 'jobs' return the list of jobs in execution, but... (4 Replies)
Discussion started by: lifedj
4 Replies

6. Shell Programming and Scripting

[SOLVED] how to use my aliases in a bash script

Hi, I confess to be stuck ... as explained here Aliases - Bash Reference Manual I added shopt -s expand_aliasesto my script ... but it didn't work. Later I've read I had to add this at the begning of my my script : . ~/.bash_aliases(of course my aliases are in this file) but again, the... (0 Replies)
Discussion started by: xib.be
0 Replies

7. Shell Programming and Scripting

SSH sessions from bash script

Hi Forum. First of all thanks for reading. I need some help here. I have been checking some other posts about this issue, but I still have problems... I'm trying to conect througn ssh to several machines to kill some process and I have problems with the " ' ' ". This is what I'm trying... (2 Replies)
Discussion started by: gtangil
2 Replies

8. Shell Programming and Scripting

SSH sessions from bash script

Hello, I had to make an ssh connection to remote server from a bash shell script. I've summarized my research and I want to share it with you. I hope it will be useful to somebody or it will get improved. Bash has an option, which is called "input redirection", I think. It is something similar to... (3 Replies)
Discussion started by: tsurko
3 Replies

9. Shell Programming and Scripting

bash ssh login script

hello anyone have done ssh login script without "expect" (automatic login from host A / user b to Host B / user b without enter any passwords)? cheers (2 Replies)
Discussion started by: modcan
2 Replies

10. Shell Programming and Scripting

bash script for ssh login-

hi. I need a bash script which can login to an other mashin via SSH and then run some commands and then return the result to my mashine. I dont know where to begin, I think first I will need a ssh connection, dont know how to make it, then , do I need a ftp connection between the 2 mashins to... (5 Replies)
Discussion started by: big_pil
5 Replies
Login or Register to Ask a Question