Linux script to access machines using hostnames / IP specified in a lookup file
I need a shell script that can access remote machines using the hostname/IP specified in the lookup file and run commands on it. I'm new to Linux scripting. Any help is appreciated. Thanks in advance.
|
Homework?
Regardless, please give some more details---e.g. do you need a secure connection? What protocols are set up on the remote machines?--eg ftp, ssh, etc. And, does each machine require a login and password? |
It is for a monitoring tool. Yes it should be a secure connection.
ssh was set up in that machine. Credentials are required. Like I said it the script should access machine from the lookup file. Expecting your reply.. |
getting the information from the lookup file is the easy part. Simply set up a loop which reads the file, process the entries (if needed), and athen pass the data to the other commands.
The hard part---at least for me---is passing commands to ssh which it will use after it has connected to the remote machine. I would start with a Google search using something like "ssh scripting" or "pass command in ssh script". Also, build up the program one step at a time---eg start by just having it login to one machine. For help on learning BASH, go here: http://tldp.org Start with the BASH Guide for Beginners, and then the Advanced BASH Scripting Guide. |
I don't have a lot of time. But, thanks anyway. One more thing, will this script get the desired result, if I have commands to be executed on the remote machine in a separate script..
for ip_addr in $(cat hostname.txt); do ssh ${ip_addr} "bash -s" < script_to_be_invoked done Thanks. |
Quote:
Quote:
I think your loop may work but I think it's more common to do: while read var; do <do stuff> done <file This reads one line at a time into "var".....reading from filename |
The for loop works,but I couldn't figure it out with while loop.
If you could provide a script with while loop using same parameters, it will be useful in future. Thanks for your replies. |
Here's a typical use of the while loop: We're going to read from a file named "inputfile"---each line will go into a variable named "lin"---, and then echo each line back to standard output.
Code:
while read lin; do |
I can execute the while loop, but how can I pass the commands to ssh like in the for loop because it has to run a script stored in the remote machine. So it has to take input from two files. Anyways thanks for your help.
|
|
All times are GMT -5. The time now is 09:21 AM. |