Skip to content

Instantly share code, notes, and snippets.

@asheborocreative
Last active December 25, 2017 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asheborocreative/6510b671ae29cf6a2712e1b9fa2135e1 to your computer and use it in GitHub Desktop.
Save asheborocreative/6510b671ae29cf6a2712e1b9fa2135e1 to your computer and use it in GitHub Desktop.
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
@asheborocreative
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment