Artificial intelligent assistant

uptime Script help 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?

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.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a54b04d0bb4854146f1be94854114bbe