uptime Script help [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am looking to build a script that will log in to multiple servers using a host file and run uptime, hostname -I and hostname
Script so far
echo"" ;
echo "hostname:" $(ssh $HOST hostname) ;
echo "IP:" $(ssh $HOST hostname -I) ;
echo "uptime" $(ssh $HOST uptime) ;
echo"" ;
What would be the best way to accomplish my goal?
shell-script ssh scripting hostname uptime
closed as off-topic by Rui F Ribeiro, msp9011, telcoM, Archemar, Jeff Schaller Aug 11 at 13:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." â Rui F Ribeiro, msp9011, telcoM, Archemar
add a comment |Â
up vote
2
down vote
favorite
I am looking to build a script that will log in to multiple servers using a host file and run uptime, hostname -I and hostname
Script so far
echo"" ;
echo "hostname:" $(ssh $HOST hostname) ;
echo "IP:" $(ssh $HOST hostname -I) ;
echo "uptime" $(ssh $HOST uptime) ;
echo"" ;
What would be the best way to accomplish my goal?
shell-script ssh scripting hostname uptime
closed as off-topic by Rui F Ribeiro, msp9011, telcoM, Archemar, Jeff Schaller Aug 11 at 13:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." â Rui F Ribeiro, msp9011, telcoM, Archemar
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am looking to build a script that will log in to multiple servers using a host file and run uptime, hostname -I and hostname
Script so far
echo"" ;
echo "hostname:" $(ssh $HOST hostname) ;
echo "IP:" $(ssh $HOST hostname -I) ;
echo "uptime" $(ssh $HOST uptime) ;
echo"" ;
What would be the best way to accomplish my goal?
shell-script ssh scripting hostname uptime
I am looking to build a script that will log in to multiple servers using a host file and run uptime, hostname -I and hostname
Script so far
echo"" ;
echo "hostname:" $(ssh $HOST hostname) ;
echo "IP:" $(ssh $HOST hostname -I) ;
echo "uptime" $(ssh $HOST uptime) ;
echo"" ;
What would be the best way to accomplish my goal?
shell-script ssh scripting hostname uptime
shell-script ssh scripting hostname uptime
asked Aug 10 at 20:47
jabur
162
162
closed as off-topic by Rui F Ribeiro, msp9011, telcoM, Archemar, Jeff Schaller Aug 11 at 13:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." â Rui F Ribeiro, msp9011, telcoM, Archemar
closed as off-topic by Rui F Ribeiro, msp9011, telcoM, Archemar, Jeff Schaller Aug 11 at 13:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." â Rui F Ribeiro, msp9011, telcoM, Archemar
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34
add a comment |Â
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Assuming you just want all output in the terminal:
#!/bin/bash
hosts_file=/path/to/file
username=youruser
while read -r host; do
hostname=$(ssh "$username@$host" hostname)
ip_addr=$(ssh "$username@$host" hostname -I)
uptime=$(ssh "$username@$host" uptime)
echo
echo "Hostname:?$hostname"
echo "IP:?$ip_addr"
echo "uptime:?$uptime"
| column -s? -t
echo
done <"$hosts_file"
This will loop through each line of your hosts_file, assigning the whole line to host
. Then it will set the hostname
, ip_addr
, and uptime
to the corresponding results on the remote machine. It will then echo those results in a columnized format.
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
add a comment |Â
up vote
0
down vote
Try (assuming your hosts in hostlist
have a correct authentication set up)
while read HOST
do read HN; read IP; read UP; printf "hostname: %snIP: %snuptime: %sn" "$HN" "$IP" "$UP"; <<< "$(ssh $HOST "hostname; hostname -I; uptime")"
done < hostlist
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Assuming you just want all output in the terminal:
#!/bin/bash
hosts_file=/path/to/file
username=youruser
while read -r host; do
hostname=$(ssh "$username@$host" hostname)
ip_addr=$(ssh "$username@$host" hostname -I)
uptime=$(ssh "$username@$host" uptime)
echo
echo "Hostname:?$hostname"
echo "IP:?$ip_addr"
echo "uptime:?$uptime"
| column -s? -t
echo
done <"$hosts_file"
This will loop through each line of your hosts_file, assigning the whole line to host
. Then it will set the hostname
, ip_addr
, and uptime
to the corresponding results on the remote machine. It will then echo those results in a columnized format.
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
add a comment |Â
up vote
1
down vote
accepted
Assuming you just want all output in the terminal:
#!/bin/bash
hosts_file=/path/to/file
username=youruser
while read -r host; do
hostname=$(ssh "$username@$host" hostname)
ip_addr=$(ssh "$username@$host" hostname -I)
uptime=$(ssh "$username@$host" uptime)
echo
echo "Hostname:?$hostname"
echo "IP:?$ip_addr"
echo "uptime:?$uptime"
| column -s? -t
echo
done <"$hosts_file"
This will loop through each line of your hosts_file, assigning the whole line to host
. Then it will set the hostname
, ip_addr
, and uptime
to the corresponding results on the remote machine. It will then echo those results in a columnized format.
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Assuming you just want all output in the terminal:
#!/bin/bash
hosts_file=/path/to/file
username=youruser
while read -r host; do
hostname=$(ssh "$username@$host" hostname)
ip_addr=$(ssh "$username@$host" hostname -I)
uptime=$(ssh "$username@$host" uptime)
echo
echo "Hostname:?$hostname"
echo "IP:?$ip_addr"
echo "uptime:?$uptime"
| column -s? -t
echo
done <"$hosts_file"
This will loop through each line of your hosts_file, assigning the whole line to host
. Then it will set the hostname
, ip_addr
, and uptime
to the corresponding results on the remote machine. It will then echo those results in a columnized format.
Assuming you just want all output in the terminal:
#!/bin/bash
hosts_file=/path/to/file
username=youruser
while read -r host; do
hostname=$(ssh "$username@$host" hostname)
ip_addr=$(ssh "$username@$host" hostname -I)
uptime=$(ssh "$username@$host" uptime)
echo
echo "Hostname:?$hostname"
echo "IP:?$ip_addr"
echo "uptime:?$uptime"
| column -s? -t
echo
done <"$hosts_file"
This will loop through each line of your hosts_file, assigning the whole line to host
. Then it will set the hostname
, ip_addr
, and uptime
to the corresponding results on the remote machine. It will then echo those results in a columnized format.
answered Aug 10 at 21:20
Jesse_b
10.5k22659
10.5k22659
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
add a comment |Â
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
This is exactly what I was looking for, thanks Jesse
â jabur
Aug 13 at 16:25
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
If I wanted to use ssh keys I could just append -i /path/to/key after ssh correct?
â jabur
Aug 13 at 16:51
add a comment |Â
up vote
0
down vote
Try (assuming your hosts in hostlist
have a correct authentication set up)
while read HOST
do read HN; read IP; read UP; printf "hostname: %snIP: %snuptime: %sn" "$HN" "$IP" "$UP"; <<< "$(ssh $HOST "hostname; hostname -I; uptime")"
done < hostlist
add a comment |Â
up vote
0
down vote
Try (assuming your hosts in hostlist
have a correct authentication set up)
while read HOST
do read HN; read IP; read UP; printf "hostname: %snIP: %snuptime: %sn" "$HN" "$IP" "$UP"; <<< "$(ssh $HOST "hostname; hostname -I; uptime")"
done < hostlist
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try (assuming your hosts in hostlist
have a correct authentication set up)
while read HOST
do read HN; read IP; read UP; printf "hostname: %snIP: %snuptime: %sn" "$HN" "$IP" "$UP"; <<< "$(ssh $HOST "hostname; hostname -I; uptime")"
done < hostlist
Try (assuming your hosts in hostlist
have a correct authentication set up)
while read HOST
do read HN; read IP; read UP; printf "hostname: %snIP: %snuptime: %sn" "$HN" "$IP" "$UP"; <<< "$(ssh $HOST "hostname; hostname -I; uptime")"
done < hostlist
answered Aug 10 at 21:32
RudiC
1,1837
1,1837
add a comment |Â
add a comment |Â
It's probably way overkill, but nagios does that as part of its monitoring.
â JohnP
Aug 10 at 21:06
What is your goal? You want all this information spit into the terminal or logged to a file? Sent to an API? Do you have ssh authorized keys setup on each host or will you need to enter a password?
â Jesse_b
Aug 10 at 21:11
This looks like job for Ansible. There is very quick howto which should be sufficient for this task: www.ansible.com/overview/how-ansible-works
â Jaroslav Kucera
Aug 11 at 7:06
I want the information to display on the terminal and I do have SSH keys set up on each host
â jabur
Aug 13 at 16:34