- Display Usage Information
This function provides the user with information on how to use the script correctly. It is called when the script is run without arguments or with invalid options.
- Parse Command-Line Options
This snippet processes the command-line options passed to the script, determining whether the user wishes to install or uninstall a package. It calls the usage function if an invalid option is provided.
- Check for Package Name Argument
After option parsing, the script checks if the package name has been specified. If not, it displays the usage information.
- Perform Action on the Host
perform_action_local function defines and calls a function to install or uninstall the package on the host system, based on the previously set ACTION variable.
- Scan for Active Hosts
The above code utilizes nmap to scan for active hosts within the subnet 192.168.0.1/24. The output is processed to extract IP addresses and hostnames.
- Identify Client Hosts and Users
This part parses the output from the previous step, filtering out the head node and preparing a list of client hosts and corresponding user names for SSH access.
- Perform Action on Client Nodes
perform_action_client function performs the specified action (install/uninstall) on each client node via SSH, then iterates over the list of client hosts and users to apply these actions concurrently.
- Finalize Operations
Finally, waits for all background operations (SSH commands) to complete, then prints a message indicating that the script has finished executing (Full Script can be found here)