Last active
December 25, 2017 00:49
-
-
Save asheborocreative/6510b671ae29cf6a2712e1b9fa2135e1 to your computer and use it in GitHub Desktop.
Check and fix hostname if it doesn't match what it should.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
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.