Skip to content

Instantly share code, notes, and snippets.

@gabeno
Created June 23, 2015 10:08
Show Gist options
  • Save gabeno/17b854cf4d509a4feba7 to your computer and use it in GitHub Desktop.
Save gabeno/17b854cf4d509a4feba7 to your computer and use it in GitHub Desktop.
A simple bash script to set time and date on ubuntu server
#!/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