![]() |
remote servers script to check health
hello all I have a script which lets you see server states but which runs locally I want to make it executable remotely for several servers from a Txt file where there are IP addresses
Code:
#!/bin/bash |
Assuming TXTFILE contains the addresses and YOURSCRIPT is your script. First, ensure your ssh key is on all the servers:
Code:
ssh-keygen # only needed if you have no key Next, copy the script to the servers. For example: Code:
for address in $(cat TXTFILE) Code:
for address in $(cat TXTFILE) |
hello tnakyou for your reply when i test your code i have this error "ssh: Could not resolve hostname 192.168.3.29:list.txt: Name or service not known" can you help me to resolve them.
thankyou |
It's a typo, sorry. I suggest you learn about ssh.
Try Code:
ssh 192.168.3.29 list.txt Code:
ssh 192.168.3.29 /home/WHATEVERYOURUSERNAMEIS/list.txt EDIT: I checked it, and in my environment, the latter solution works. The former doesn't. |
You do not need to scp and chmod your script.
Directly pass+run the script to/on the remote host: Code:
for address in $(grep '^[^#]' TXTFILE) The -s allows script arguments to follow. |
Quote:
Allowing comments on their own line and as suffixes can be achieved with: Code:
for address in $(sed 's/#.*//' TXTFILE) |
All times are GMT -5. The time now is 04:16 AM. |