Jump to content
dave

Show uptime notification

Recommended Posts

I created a small workflow displaying the system's uptime in a notification.

 

Download

 

This is also useful as an example for integrating scripts in your workflow.

 

Enjoy.

 

- David

 

EDIT: corrected the download link to a private hosting provider, wikisend appears to be dubious. Sorry for any inconvenience.

Edited by dave

Share this post


Link to post

I was wondering about the 12MB file too. "small workflow"?? And didn't install it.

by the way I was wondering.. not talking about anyone here but can fraudulent people do strange things with alfred workflows when they distribute them here?

Share this post


Link to post

@DJay — There is the possibility. Since the workflows allow for pretty much any script to be run, then malicious code is easy to install (even if it is just to use curl to download something else). Currently, there isn't any mechanism to automatically flag a workflow as having malicious code. Any user can reply to a forum post declaring malicious code and report the post that has it, but those are the only mechanisms that exist currently.

 

With the Extras page for the Alfred2 website, there will be some featured workflows that will be safe and vetted (I'm sure). With Olivier's repo, currently each workflow and theme needs to be approved, but I'm not sure how much checking will be involved in there because I'm sure that there will be many submissions, and it would take quite a lot of volunteer time to sort through them all.

 

Anything posted here can be vetted only by the community. I have faith that 99% of the users here will post great workflows, and users who have posted many workflows before can easily be trusted, but there is always the possibility that someone can upload a malicious workflow.

 

Be diligent?

Share this post


Link to post

@rice.shawn — Thanks a lot for these information and your thoughts. I really appreciate the community here. swapping ideas and great workflows.

And of course I think as you mentioned the most girls and boys here are honest. :)

Edited by DJay

Share this post


Link to post

Oh, wait. That was not supposed to happen. Let me check. Maybe wikisend wasn't that good an idea for hosting the file.

Share this post


Link to post

@Dave Thanks for the workflow and sharing. Sometimes I check the uptime so thats an easy way.

Danke auch für das Nusseckenrezept.  ^_^

Share this post


Link to post

@Dave Thanks for the workflow and sharing. Sometimes I check the uptime so thats an easy way.

Danke auch für das Nusseckenrezept.  ^_^

 

You're welcome. :-)

Share this post


Link to post
Guest

And if you just want to know the days, hours and minutes since last reboot, you can use the following term:

uptime | sed -e 's/,.[0-9]*.user.*//' -e 's/^.*up *//'

 

this would f.e. result in

2 days,  7:28

Share this post


Link to post

Just in case anyone would be interested: Another method of formatting the uptime output:

 

 

 

uptime | awk '{sub(/[0-9]|user,|users,|load/, "", $6); sub(/mins,|min,/, " minutes", $6); sub(",", " minutes", $5); sub(":", " hours ", $5); sub(/hrs,|hr,/, " hours", $4); sub("h ", " hours ", $4); sub(/days,/, " days ", $4); sub(":", " hours ", $3); sub(",", " minutes", $3); print "" $3 $4 $5 $6}' | sed -e 's/ 1 days/ 1 day/g' -e 's/ 1 hours/ 1 hour/g' -e 's/1 minutes/1 minute/g' -e 's/usermin//g'
 

 

 

This will output, in my case: "19 days 17 hours 45 minutes"

It's just a tad more human readable, although I find the length of the awk to be a bit ironic

Share this post


Link to post

Nice RodgerWW.. Thanks.

 

But looks a bit strange here.

Would great to have "0 days, 8 hours, 28  minutes".

Whats the 1user minutes?

 

Bildschirmfoto%202013-04-08%20um%2018.02

Edited by DJay

Share this post


Link to post

I would prefer to have the script distinguish between day/days, hour/hours and minute/minutes if moving from the current really plain approach to a more sophisticated implementation. No need for a cryptic perl/sed/awk script, though. Simple, understandable php, python or shell is fine. Anyone?

Share this post


Link to post

Nice RodgerWW.. Thanks.

 

But looks a bit strange here.

Would great to have "0 days, 8 hours, 28  minutes".

Whats the 1user minutes?

 

Bildschirmfoto%202013-04-08%20um%2018.02

 

 

OK, in lieu of using "uptime" I personally found "system_profiler SPSoftwareDataType | grep 'Time since boot'" to be a bit easier to parse with only one return, as I am very new to awk and grep.

 

 

So, the initial command "system_profiler SPSoftwareDataType | grep 'Time since boot'" will return:

 

Time since boot: 20 days 11:19

 

NEW code:

 

 

system_profiler SPSoftwareDataType| grep 'Time since boot' | awk '{sub(/Time since boot:/, ""); sub(":", " hours ", $3); sub("", "minutes", $4);print "" $0}'| sed -e 's/ 1 days/ 1 day/g' -e 's/ 1 hours/ 1 hour/g' -e 's/00 minutes/0 minutes/g' -e 's/01 minutes/1 minute/g' -e 's/02 minutes/2 minutes/g' -e 's/03 minutes/3 minutes/g' -e 's/04 minutes/4 minutes/g' -e 's/05 minutes/5 minutes/g' -e 's/06 minutes/6 minutes/g' -e 's/07 minutes/7 minutes/g' -e 's/08 minutes/8 minutes/g' -e 's/09 minutes/9 minutes/g'

Will return:

 

20 days 11 hours 19 minutes

 

I'm using awk to to remove "Time since boot:", the time separator, and also to add the hours and minutes.

I'm using sed to modify the plural form of days/hours/minutes, and also to remove leading zeros.

 

I'm not sure how the singular days are displayed with 'Time since boot" (as I'm currently on 20 days and have no real reason to reboot my system currently), so I left out that sed formatting, but it can be added easily.

 

 

Edited by RodgerWW

Share this post


Link to post

I would prefer to have the script distinguish between day/days, hour/hours and minute/minutes if moving from the current really plain approach to a more sophisticated implementation. No need for a cryptic perl/sed/awk script, though. Simple, understandable php, python or shell is fine. Anyone?

 

I would agree 100% on this ... I WISH I knew how to do this myself ... Would be awesome to start at the epoch time, remove current time, and scriptually only show singular for year/month/day/week/hour/min ... seconds might be going a little too far though, lol. Oh, and also remove leading zeros.

 

So the perfect output: " 1 year 35 days 12 hours 1 minute "

Edited by RodgerWW

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...