If you have a jump-server with connection to you target hosts, it is better to do the same job (command) via script. The easiest way if you prepare a script on your jump-server which run you command on all of your host. The script’s output (result of command on remote host) will be logged in give path / file what you configured on script & it is visible also on stdout.
Explanation of script:
Required as in here you declare that you will use bash. If you write KornShell script, in here you will declare “ksh”
Define variables what we will invoke during script & assign these to positional parameter.
If our last positional parameter is empty (so not configured correctly) script prints out the basic usage of it & exit from script.
Password section of script.
At the moment script is configured to ask for password when you start to run it. It is the secure-way to run the script as the password will be stored in protected way, but in this mode user-interact needed (type password). The another way when you would like to run it fully automatically.
You can configure it to fully automatically (like when you would like to use it as a cron-job). In this mode the biggest disadvantage that you password will be store it in plain-text on your script file.
Start of the while loop. These command run on the host where you started the script.
Command to ssh to the remote host. Timeout was used as in your list one of the host not answer, the script continue running.
Command which will be run on remote host(s) as root. Command will be used from “$REM_COMMAND” variable, which is the “$3” positional parameter.
Close while loop which’s source is “$HOST_SOURCE” ($4) & log it to “$LOG_DESTINATION”
To run it. you must to add executable-bit for the file & must tbe add five parameter for it. If you don’t know, which order, just start the script without parameters, it will print out the usage of it.
The source-file’ format:
If you would like to use “/etc/hosts” as source, please change SSH-command line from :