my desktop CMOS battery is not working, therefore I have to set time and date each time my computer starts up. I want to create a shell script to automate the setting of date and time on my computer after each boot is complete. options that exist include: 1. buying a CMOS battery :- am considering this, but for the meantime a shell script will do. 2. using NTP to synchronize time and date with internet servers :- am not connected to the internet.
If the system has no way to know the hour, the only thing you can do is trying to save the date-time on shutdown and reload on reboot (as you suggested).
Warning: The following instruction should work with a SystemV-type init system: I have not tested it (I am on a windows machine now) so you have to test them and take them with a bit of salt --- there could be typos.
Warning2 I think that upstart (the modern Ubuntu implementation of init scripts) respect it, but your mileage can vary: test and experiments are needed.You can start from here if you want to do it in a fancier way.
To save the date on shutdown/reboot, you can add a script to the
All the following commands must be issued as root. Use your preferred method...
So you can create a script
make it executable and then link it (the
Then at reboot you want to read the file. There are a lot of place where to put it, the easiest being
Edit it and put near the start:
...and that should be it. Happy hacking!