Created
June 23, 2015 10:08
-
-
Save gabeno/17b854cf4d509a4feba7 to your computer and use it in GitHub Desktop.
A simple bash script to set time and date on ubuntu server
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 | |
################################################################################################# | |
# A simple script to set time and date on a ubuntu server # | |
# # | |
# Adapted from this short article: # | |
# https://www.garron.me/en/linux/set-time-date-timezone-ntp-linux-shell-gnome-command-line.html # | |
# # | |
# How to run: # | |
# 'sudo bash set_time_date.sh' # | |
# # | |
################################################################################################# | |
id -u | grep -q ^0$ || { echo "you need to be root"; exit 1; } | |
echo "=============================" | |
echo "Lets fix date" | |
echo "=============================" | |
read -p "Please provide date (format=YYYYMMDD): " | |
date +%Y%m%d -s "$REPLY" | |
echo "=============================" | |
echo "Lets fix time" | |
echo "=============================" | |
read -p "Set time (format=HH:MM:SS): " | |
date +%T -s "$REPLY" | |
echo "successfully set date and time to: " | |
date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment