Advertisement
geofferey

[BASH] - Set Time Via NTP/file for Dead CMOS Battery

Mar 7th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script was designed to keep time for Laptop's running *NIX systems with dead CMOS batteries
  4. # Specfically Mac OSX but it can be adapted to other *NIX Systems, use a launch daemon to run on osx
  5. # and create a .conf file named "time.conf" in /usr/share/fixes/time containing variable TIME=
  6. # Check out my paste for the other pieces to this script
  7.  
  8.  
  9. #Load variables from .conf file
  10.  
  11. . /usr/share/fixes/time/time.conf
  12.  
  13.  
  14. #Variables
  15.  
  16. DATE=$(date +%m%d%H%M%Y)
  17.  
  18.  
  19. #Check year & set time from variable in .conf file
  20.  
  21. [ $(date +%Y) = 1969 ] && date $TIME
  22.  
  23.  
  24. #Update time via ntp server
  25.  
  26. ntpdate -u $(systemsetup -getnetworktimeserver|awk '{print $4}')
  27.  
  28.  
  29. #Save time to variable in .conf file
  30.  
  31. sed -i -e "s/^TIME=.*/TIME=$DATE/" /usr/share/fixes/time/time.conf
  32.  
  33.  
  34. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement