Check and fix hostname if it doesn't match what it should.
#!/bin/bash | |
CORRECT_HOSTNAME="hostname.mydomain.com" | |
CURRENT_HOSTNAME="$( hostname )" | |
if [[ $CORRECT_HOSTNAME != $CURRENT_HOSTNAME ]]; then | |
hostname $CORRECT_HOSTNAME | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
asheborocreative commentedDec 25, 2017
Updated so it's the short version with no echoing. You can run this via a cronjob to force fix your hostname in the event that it has changed. This can happen with some VPS and Dedicated Server providers when the instance is rebooted. It's really annoying when that happens so this can be used to help fix it when it does.