1 | initial version |
To stop a bash script from running if the hostname is not "x4", you can use the following code snippet at the beginning of your script:
#!/bin/bash
required_hostname="x4"
current_hostname=$(hostname)
if [ "$current_hostname" != "$required_hostname" ]; then
echo "This script can only be run on the host: $required_hostname"
exit 1
fi
This code will compare the current hostname with the required hostname ("x4" in this case). If the hostnames do not match, the script will print an error message and exit with a status code of 1, indicating an error. If the hostnames match, the script will continue executing the following commands.