You are not logged in.
Hello! I hope I am not posting this at the wrong place.
My laptop's CMOS battery has given up, and the time-date are reset at each reboot.
I currently use timedatectl set-time "<date time>" to set the clock at each boot, but it is too much hassle. So I thought of syncing my clocks with my android devices.
Here is the command I tried: (adb already initialized)
sudo timedatectl set-time "$(adb shell date +"%F %T")"
It gives me the following error:
Failed to parse time specification: 2013-01-09 14:46:42
What really got me confused is that fact that the commands:
sudo timedatectl set-time "$(date +"%F %T")"
and
sudo timedatectl set-time "$(adb shell date +"%F") 14:30:00"
Works perfectly as intended, but are of no use of course. What could be causing the trouble?
Can someone point some otherway of scripting to sync my clocks at boot, maybe from some other source of time perhaps? I am aware of NTP, but Internet connectivity at boot is not guaranteed, whereas I almost always have my android device with me.
Last edited by ufizo (2013-01-09 15:45:33)
Offline
I am aware of NTP, but Internet connectivity at boot is not guaranteed
It doesn't have to be. Just set up NTP to run whenever you connect.
Offline
I understand that, but I rather have to stay offline for long periods.
Offline
Different approach - new CMOS battery?
never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::
Offline
Different approach - new CMOS battery?
I'll buy a new laptop soon for that matter. But for curiosity's sake I want to find out whats wrong with my approach.
Offline
Break it apart for troubleshooting:
VAR="$(adb shell date +"%F %T")"
echo $VAR
sudo timedatectl set-time "$VAR"
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Break it apart for troubleshooting:
VAR="$(adb shell date +"%F %T")" echo $VAR sudo timedatectl set-time "$VAR"
echo $VAR
gives:
2013-01-09 19:31:41
and
sudo timedatectl set-time "$VAR"
still gives
Failed to parse time specification: 2013-01-09 19:31:41
Interestingly,
If I set another variable as:
VAR1="2013-01-09 19:31:41"
it works.
echo $VAR1 && echo $VAR
gives:
2013-01-09 19:31:41
2013-01-09 19:31:41
Last edited by ufizo (2013-01-09 14:06:37)
Offline
What do you get if you do this:
date +"%F %T" -d "$VAR"
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
2013-01-09 19:31:41
Offline
There's probably some sort of newline, EOF, or non-printing character at the end of what is returned from adb.
Try changing the echo to the following to see if the brackets show up right at the beginning and end of the date:
echo "[$VAR]"
And/or you could use the bash string manipulation to remove the tail end of the string - I don't remember the propper invocation of the top of my head, but it is easily looked up. Or yet as another alternative, you could "sed" out any unexpected characters:
VAR="$(adb shell date +"%F %T" | sed 's/[^0-9: -]//g )"
Last edited by Trilby (2013-01-09 15:12:29)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Since the length of the timedate string is fixed, you could always take the first 19 characters: ${string:0:19}
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
There's probably some sort of newline, EOF, or non-printing character at the end of what is returned from adb.
Try changing the echo to the following to see if the brackets show up right at the beginning and end of the date:
echo "[$VAR]"
And/or you could use the bash string manipulation to remove the tail end of the string - I don't remember the propper invocation of the top of my head, but it is easily looked up. Or yet as another alternative, you could "sed" out any unexpected characters:
VAR="$(adb shell date +"%F %T" | sed 's/[^0-9: -]//g )"
Yes, that was the issue. Removing the tail end fixed the issue. Thanks.
Since the length of the timedate string is fixed, you could always take the first 19 characters: ${string:0:19}
That also gets it done. Thank you.
Offline
*oops* yes, just taking the first 19 characters is much easier, and more efficient. Stick with that for the long term solution.
If this is now working, please mark the thread as solved by editting your initial post to prepend "[SOLVED]" to the title.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
2013-01-09 19:31:41
Sorry, I had to go out. My suggestion was to put the local date call in the mix:
sudo timedatectl -set-time "$(date -d "$(adb shell date +"F% T%")" +"F% T%")"
Can't test as don't have adb - if the quoting can't be worked out then having it in two steps with a variable was another suggestion.
I did also think there as an odd non-printing character in there, and thought this would get rid of it whatever and wherever it was. It's probably no better and possibly worse than the suggestions above.
Anyway, just adding it for the record.
Last edited by skanky (2013-01-09 16:15:46)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline