Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Show system birthday #37

Closed
tudurom opened this issue Jan 29, 2016 · 59 comments
Closed

Show system birthday #37

tudurom opened this issue Jan 29, 2016 · 59 comments

Comments

@tudurom
Copy link
Contributor

tudurom commented Jan 29, 2016

On Linux it's easy: you can read the day when /lost+found was created.

@dylanaraps
Copy link
Owner

Sounds like something fun to add, I'll add it to my TODO list.

@dylanaraps
Copy link
Owner

What does this command output? ls -alct / |tail -1 | awk '{print $6, $7, $8}'

If the command above doesn't work then I'm not sure about how we can get
this information without root privileges.

@ladislavskufca
Copy link

System birthday like time when it was installed? I am getting "Oct 11 00:01" but thats not even close to my OS X birthday. 😄

@dylanaraps
Copy link
Owner

Yup!

I can't seem to get the correct value without root privileges which means that this feature won't be coming any time soon.

@ladislavskufca
Copy link

After some digging in system logs here in OS X (should I stop saying OS X, because I think that you already found out that its my system 😄 ), I found that Oct 11 is pretty accurate actually. Found out I made clean install off OS X on Oct 10! But year is still missing in your command (and you can't just grep it from ll, or?).

@dylanaraps
Copy link
Owner

What does this command output? This is the same as above but it'll print more info.

ls -alct / | tail -1

@ladislavskufca
Copy link

d-wx-wx-wt 2 root wheel 68 Oct 11 00:01 .Trashes

@dylanaraps
Copy link
Owner

Ah, we still don't get the year.

@dylanaraps
Copy link
Owner

I can't seem to find any other way of getting the birthday without requiring root.

@ladislavskufca
Copy link

Actually, you can. Your ls -alct / | tail -1 is missing -T, which, refering to manual does:

When used with the -l (lowercase letter ``ell'') option, display complete
time information for the file, including month, day, hour, minute, second,
and year.

So yeah, running ls -alctT / | tail -1 returns d-wx-wx-wt 2 root wheel 68 Oct 11 00:01:17 2015 .Trashes which is awesome! Just awk that.

@dylanaraps
Copy link
Owner

Oh neat!

Ok, it turns out that the flag is different on linux. It's --full-time here and it prints a similar output. I'll start work on adding this now! :)

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

Another option would be getting the birthday in an OS-specific manner. For example, on Arch you can get the OS birthday by reading the first line in /var/log/pacman.log. This command prints the date and time when the OS got installed.

head -n 1 /var/log/pacman.log | tr -d '[]' | awk '{print $1, $2}'

Prints: 2015-11-27 16:40.

A similar command can be used on Ubuntu based OS's.

@dylanaraps
Copy link
Owner

The simpler we can get the function to be the better, does ls -alct --full-time / | tail -1 include the birthdate for you @tudurom?

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

Yeah, it works. A better variant is this:

ls -alct --full-time / | tail -1 | awk '{print $6}'

@ladislavskufca
Copy link

Oh ok, if command here is different and you have to "if" them for different distros, please use this one for OS X then: ls -alctT /var/log/CDIS.custom.
Prints out: -rw-r--r--@ 1 root wheel 12 Oct 11 07:18:56 2015 /var/log/CDIS.custom.
It is more accurate because it represents first time the installer was started: Oct 11 07:18:56 2015.

@dylanaraps
Copy link
Owner

@tudurom: Awesome!

@mclado:

  • Will this work for every OS X system?
  • Do we need the tail -1 part for this new command?

@ladislavskufca
Copy link

Yes, CDIS.custom is always here. Even in cases where installer fails and even in older OS X versions.

@dylanaraps
Copy link
Owner

Awesome!

@dylanaraps
Copy link
Owner

I'll also add a config option to convert the output to a prettier format. So 2015-11-27 will be converted to 27th November 2015 and etc.

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

Didn't specified; the above command yields 2015-11-27.

An even better one would be

ls -alct --full-time / | tail -1 | tr ':' ' ' | awk '{print $6, $7 ":" $8}'

That shows 2015-11-27 00:39.

@dylanaraps
Copy link
Owner

The ls -alct --full-time / gives me a totally different output when run from inside the script. I'm confused as to why.

Birthday: 1970-01-01 10:00

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

Try this:

ls -alct --full-time / | grep "lost+found"

@dylanaraps
Copy link
Owner

This works, awesome!

@dylanaraps
Copy link
Owner

I pushed a version for you guys to test to master. The birthday line is disabled by default and can be enabled with info "Birthday" birthday.

What does the output look like?

@ladislavskufca
Copy link

Fine with me.
Whats wrong with font?

View post on imgur.com
<script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

@dylanaraps
Copy link
Owner

The font is the GTK theme font.

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

Looks good. Another enhancement would be specifying if you want to show the time.

pic

@dylanaraps
Copy link
Owner

I'm working on converting the output to a prettier format, here's what mine looks like now:

img

What do you guys think?

@dylanaraps
Copy link
Owner

Another enhancement would be specifying if you want to show the time.

I'll add this too!

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

What the hell that's too small.

@dylanaraps
Copy link
Owner

It takes a while to get used to it. :)

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

I will end this off-topic discussion by saying my font's called erusfont. Sorry for spamming, watchers and issue contributors.

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

May I close this issue?

@dylanaraps
Copy link
Owner

I'm about to push the finished function, lets leave this open until you guys test it out.

@dylanaraps
Copy link
Owner

I just pushed it to master.

There are two new flags/options:

  • --birthday_shorthand and $birthday_shorthand to shorten/lengthen
    the output of birthday.
  • --birthday_time and $birthday_time to show/hide the time in the output.

If it works, we can close the issue!

@tudurom
Copy link
Contributor Author

tudurom commented Jan 30, 2016

In my case it works. Does it work on Windows?

@dylanaraps
Copy link
Owner

I'm testing BSD at the moment and it doesn't work. I'll check Windows now.

@ladislavskufca
Copy link

OS X: not working, its blank except if I use --birthday_shorthand flag.

@dylanaraps
Copy link
Owner

Can I see the shorthand output?

@ladislavskufca
Copy link

Birthday: Oct 11 2015 07:18

@dylanaraps
Copy link
Owner

What's the output of date -d"Oct 11 2015 07:18" "+%a %d %b %Y %l:%M %p"?

@ladislavskufca
Copy link

Ugh, something is different. Again.

usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

@dylanaraps
Copy link
Owner

This is the error I was looking for! :)

@dylanaraps
Copy link
Owner

Look in man date and tell me what the description of the -d flag is.

This is what it is on linux:

-d, --date=STRING
          display time described by STRING, not 'now'

@ladislavskufca
Copy link

@dylanaraps
Copy link
Owner

Thanks

@dylanaraps
Copy link
Owner

What about this command?

date -j -f"Oct 11 2015 07:18" "+%a %d %b %Y %l:%M %p"

@ladislavskufca
Copy link

Nope :/

@dylanaraps
Copy link
Owner

What about this?

date -j -f "%a %d %b %Y %l:%M %p" "Oct 11 2015 07:18" "+%s"

@ladislavskufca
Copy link

It says illegal time format. This "+%s" actually just converts date to seconds or smth, because running date -j -f "%a %b %d %T %Z %Y" "date" does Sat Jan 30 13:10:18 CET 2016 and appending "+%s" converts to 1454155814.

@dylanaraps
Copy link
Owner

Awesome, we just need to use the right time format now!

@dylanaraps
Copy link
Owner

Also BSD and OS X share the same date flags, so I'm booting up a virtual machine to test.

@dylanaraps
Copy link
Owner

I've figured it out! :)

I'll push it to master in a sec.

@ladislavskufca
Copy link

Works like charm now. Except --birthday_time flag does nothing.

@dylanaraps
Copy link
Owner

Weird, I'll see if I can reproduce this.

@ladislavskufca
Copy link

Oh sorry, my bad. Works in all combinations! You can close this now.

@dylanaraps
Copy link
Owner

Awesome!

The function still doesn't work with BSD and Windows but I can work on this locally.

nsavinda pushed a commit to nsavinda/unifetch that referenced this issue Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants