SSh to some IPs in a script
I used this code to ssh some IPs so that after any ssh and doing my commands I can ssh another IP.
Code:
while read IP stdin: is not a tty Pseudo-terminal will not be allocated because stdin is not a terminal. |
Is it key-based authentication or password?
|
Quote:
|
Well, you're using -n which teels ssh to go to the background (this doesn't work with passwords).. A great way is to use -f instead.. But in your situation, I wouldn't recommend any of them..
|
Quote:
Cannot fork into background without a command to execute. |
Yes, well, reading about the -f option was implied (I guess you did know what -n does!? don't you) .. Anyway, just don't use any options and it should work..
|
Quote:
stdin: is not a tty and I can't run my commands |
What are you trying to do ?
If all you need to do is log in remotely then ssh user@host should do it. e.g.: Code:
[schneidz@hyper ~]$ hostname |
Quote:
I need to ssh some IPs in loop and do some different commands!!! |
How do you run your script? Make sure you do it from a console (/emulator)... Since it needs to ask your password, you need an actual console (that's what tty means)
|
Quote:
|
Quote:
|
Quote:
|
Code:
usr=me # ./do_stuff # User: root # IP: <Some IP> root@<Some IP>'s password: # exit logout Connection to <Some IP> closed. # User: nagios # IP: <Some IP> nagios@<Some IP>'s password: # exit logout Connection to <Some IP> closed. # User: exit # IP: ssh: Could not resolve hostname : No address associated with hostname Gives you some nice prompts as well :) So what you can do is put whatever user/IP required to login then it will prompt with pass. Access box do whatever you want and on exit will be presented with user/IP selection again. Seems a bit pointless as you are still typing the user/IP anyway it would take just as long to type unless you are automating passing in usr/IP: ssh root@some_ip Could default input on the reads with -i if you always going in as root for instance. Code:
read -e -p " # User: " -i "root" usr #(for example) |
All times are GMT -5. The time now is 09:35 PM. |