0

What sequence of awk, sed, and/or cut commands can I use to take the date at the end of /proc/version, for example

Linux version 4.15.7 (user@system) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)) #233 SMP Sat Mar 10 11:40:22 EST 2018

and convert it to a format that can be passed to the date command to set the system time? This is going to be used to set the default time of an embedded Linux system, so it needs to work with the Busybox utils.

  • 1
    What have you tried so far? And do you know about the fake-hwclock package available for systems with no battery backed RTC capability? – roaima Sep 30 '18 at 20:37
  • @roaima This is for an initramfs that listens for recovery attempts and if it doesn't get any, tries to mount the real root filesystem and boot. I would like the default startup time to be as late as possible (but not in the future) without updating the initramfs. I did a quick manpage search, and fake-hwclock doesn't seem like it fits this purpose; any time it wrote to the 'file system' would be lost when the real file system gets mounted or the system reboots. – Billy Sep 30 '18 at 20:47
  • Billy that's fine. Didn't want you not to know about that package, and since I didn't have knowledge of your environment I couldn't call whether or not it might be useful to you. – roaima Sep 30 '18 at 20:54
  • @roaima No problem at all. That package might actually come in handy for the post-initramfs system, with has a non-volatile filesystem. – Billy Sep 30 '18 at 20:56
4

date is fairly lenient and will accept about anything that makes sense. Looking at your /proc/version you just need to cut it on SMP:

date -s "$(sed 's/.* SMP //' /proc/version)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.