Syntax Needed for xfce Genmon tuptime Print-out [SOLVED]

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Syntax Needed for xfce Genmon tuptime Print-out [SOLVED]

Post by jakfish »

With a GPD Pocket 1/LM 19.3 xfce, I'm trying to use tuptime rather than uptime to maintain a persistent uptime.

In Manjaro/GPD Pocket 3, this works:

Code: Select all

sudo tuptime | awk -F'=' '/System uptime:/ {print substr($2, 1, length($2)-3)}'
Producing e.g.:

Code: Select all

 6h 17m
in genmon/panel.

But Arch/Tuptime produces different reading/syntax when using

Code: Select all

sudo tuptime
In LM, it's:

Code: Select all

jake@p1:~$ sudo tuptime
System startups:	4   since   11:05:59 AM 10/01/2022
System shutdowns:	3 ok   <-   0 bad
System uptime: 		97.84 %   -   52 minutes and 36 seconds
System downtime: 	2.16 %   -   1 minute and 10 seconds
System life: 		53 minutes and 46 seconds

Largest uptime: 	27 minutes and 54 seconds   from   11:31:51 AM 10/01/2022
Shortest uptime:	3 minutes and 37 seconds   from   11:13:33 AM 10/01/2022
Average uptime: 	13 minutes and 9 seconds

Largest downtime:	24 seconds   from   11:13:09 AM 10/01/2022
Shortest downtime:	23 seconds   from   11:31:28 AM 10/01/2022
Average downtime: 	23 seconds

Current uptime: 	27 minutes and 54 seconds   since   11:31:51 AM 10/01/2022
What I'd like to print is simply the System uptime in shortened form: e.g.: "52m" or "2h 52m"

This syntax is far above my paygrade so any help from veterans would be much appreciated.
Last edited by LockBot on Sat Apr 01, 2023 10:00 pm, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
zcot
Level 9
Level 9
Posts: 2803
Joined: Wed Oct 19, 2016 6:08 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by zcot »

So, you want System life then? -no, right, that includes downtime.

That current script is checking for =, but the output shown is using -.

How do you want it to handle days? and what about seconds? Do you have a modified locale setting so it only uses hours/minutes?
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by jakfish »

>> That current script is checking for =, but the output shown is using - << Yes, I noticed the same thing.

Code: Select all

=
comes up in Manjaro but not in LM.

Code: Select all

System uptime: 		97.84 %   -   52 minutes and 36 seconds
This is the like I'd like to modify, shorten down to

Code: Select all

 6h 17m
Hours/minutes only; no need for seconds.

Thanks for any advice.

Edit: using your observation, I substituted

Code: Select all

-
for

Code: Select all

=
then ran original Manjaro command to produce this:

Code: Select all

jake@p1:~$ sudo tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2)-3)}'
   1 hour, 18 minutes and 52 seco
Possible to reduce that to

Code: Select all

1h 18m
?
User avatar
zcot
Level 9
Level 9
Posts: 2803
Joined: Wed Oct 19, 2016 6:08 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by zcot »

Well, here's a start anyway:

Code: Select all

tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2)-10)}'
:D

On my system Mint 20.x, using tuptime version 4.1.0 the output looks like this:

Code: Select all

   1 day, 21 hours, 38 minutes, 2 seco
removing 10 characters, as the above example:

Code: Select all

   1 day, 21 hours, 38 minutes,
One idea might be to only use the first 2 groupings, in this case minutes would also be eliminated. But prior to the 24 hour mark it would at least show hours and minutes only.

Are you using tuptime 5.2.1?


But probably, I think you need quite a different line.

Maybe use tuptime -s which would produce(at least on this version):

Code: Select all

System uptime: 		100.0%   -   165369
-and then process that as desired.

Is that going to work in genmon when you require sudo? do you even require sudo?
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by jakfish »

For some reason, I needed sudo in Manjaro, but I'm already sudo 24-7 in /etc/sudoers.

Code: Select all

tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2)-32)}' | awk ' { print $1 "h "}'
2h

I fumbled enough to add an "h"

As for your suggestion for a second group (minutes), what would be the syntax to produce just the number of minutes?

I really appreciate you hanging in there like this.
User avatar
zcot
Level 9
Level 9
Posts: 2803
Joined: Wed Oct 19, 2016 6:08 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by zcot »

I tested your line, but on my system the first number refers to day, so I do get: 2h but it should be 2d

Let's back up, if we just peel off the front of the result, like you just did, we don't need the earlier removal at the end and here's why. -3, or -10, or -32 is not really proper if the ending is 1 hour, 1 minute, 1 second. The output is given properly from tuptime so if it's 1, then the result is not plural. So anyway...

bring the original line back, lets eliminate the ending truncation:

Code: Select all

tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2)-3)}'
tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2))}'
Now use your next effort on the front, from that point:

Code: Select all

tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2))}' | awk '{print $1,$2,$3,$4}'
Are you going to deal with d and h and m? My system has day at the first column(I'm on day 2), so just format that?

Code: Select all

tuptime | awk -F'-' '/System uptime:/ {print substr($2, 1, length($2))}' | awk '{print $1$2,$3$4}'
-that's not really there though.

it's bulky, but you can use the previous substr option with this previous line, $2 and $4 get the substr treatment.
rfmoz
Level 1
Level 1
Posts: 2
Joined: Sun Oct 02, 2022 6:28 am

Re: Need Syntax Help for xfce Genmon Print-out

Post by rfmoz »

Parsing the output of Tuptime is easy when the CSV option is used.

Simply grep the desired line, extract the right quoted block and filter by spaces to forguet the seconds from 1 to 3:

Code: Select all

$ tuptime -c | grep 'System uptime'
"System uptime","67.27%","=","82d 9h 27m 16s"

Code: Select all

$ tuptime -c | grep 'System uptime' | cut -d \" -f8
82d 9h 27m 16s

Code: Select all

$ tuptime -c | grep 'System uptime' | cut -d \" -f8 | cut -d ' ' -f1-3
82d 9h 27m
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by jakfish »

Can't thank you folks enough for weighing in. For some reason, I'm not getting the same print-out from your suggested commands. E.g.:

Code: Select all

tuptime -c | grep 'System uptime' | cut -d \" -f8
9 hours, 20 minutes and 53 seconds
Also, since the print-out is in genmon on the xfce panel, serious abbreviation is needed.

So I took everybody's advice and rolled tuptime into two side-by-side genmons:

Code: Select all

jake@p1:~$ tuptime -c | grep 'System uptime' | cut -d \" -f8 | cut -d ' ' -f1-1 | awk ' { print $1 "h "}'
9h

Code: Select all

jake@p1:~$ tuptime -c | grep 'System uptime' | cut -d \" -f8 | cut -d ' ' -f3-5 | awk ' { print $1 "m "}'
25m
Not the most elegant solution, but it does seem to work so far.

Thanks again for your patience and your help.
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by jakfish »

No, my scripts failed after a reset of tuptime. Since 19.3 is the one Mint that really plays nice with the Pocket 1, I'm stuck with tuptime ver 3.3, and that's why I'm not getting your clean printouts. E.g."

j

Code: Select all

ake@p1:~$ tuptime
System startups:	2   since   11:15:00 AM 10/02/2022
System shutdowns:	1 ok   <-   0 bad
System uptime: 		98.69 %   -   29 minutes and 10 seconds
System downtime: 	1.31 %   -   23 seconds
System life: 		29 minutes and 33 seconds

Largest uptime: 	22 minutes and 25 seconds   from   11:22:08 AM 10/02/2022
Shortest uptime:	6 minutes and 45 seconds   from   11:15:00 AM 10/02/2022
Average uptime: 	14 minutes and 35 seconds

Largest downtime:	23 seconds   from   11:21:45 AM 10/02/2022
Shortest downtime:	23 seconds   from   11:21:45 AM 10/02/2022
Average downtime: 	23 seconds

Current uptime: 	22 minutes and 25 seconds   since   11:22:08 AM 10/02/2022
Ver 3.3 apparently changes the print format once an hour passes, so cut and other editing can't be persistent. Too bad.
User avatar
zcot
Level 9
Level 9
Posts: 2803
Joined: Wed Oct 19, 2016 6:08 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by zcot »

jakfish wrote: Sun Oct 02, 2022 10:40 am I'm not getting the same print-out
I guess with the different versions, the output has developed.
rfmoz wrote: Sun Oct 02, 2022 6:42 am easy when the CSV option is used.
Yes! :D

I wasn't going to jump right into easy. I'm not familiar with the program, looks pretty cool though! But, yea, my mind doesn't think in awk so I would already lean into grep, or just go large and parse the single big integer out. :lol:

19.3, that's bionic, so tuptime 3.3.3 Can you give some word about it? -does that not have csv output? Also, day was added later? Nice work btw. :wink:

It looks to me like with the dependencies it shouldn't be an issue at all to use the current github build.
jakfish
Level 1
Level 1
Posts: 21
Joined: Tue Sep 24, 2019 1:05 pm

Re: Need Syntax Help for xfce Genmon Print-out

Post by jakfish »

You are very right; to upgrade tuptime, just one dependency needs addressing:

Code: Select all

wget http://ftp.kr.debian.org/debian/pool/main/i/init-system-helpers/init-system-helpers_1.60_all.deb
sudo apt install ./init-system-helpers_1.60_all.deb
Once done, you can install tuptime 5.2 on Tricia 19.3

Now my original Manjaro command works in LM:

Code: Select all

jake@p1:~$ sudo tuptime | awk -F'=' '/System uptime:/ {print substr($2, 1, length($2)-3)}'
  36m
Even the = works again.

Never would have thought that I could jump so many versions with just one dependency to fix.

Thank you all again. I understand just a fraction of this syntax but that's more than I knew before I posted.
rfmoz
Level 1
Level 1
Posts: 2
Joined: Sun Oct 02, 2022 6:28 am

Re: Syntax Needed for xfce Genmon tuptime Print-out [SOLVED]

Post by rfmoz »

If you already have a working Tuptime installed and Python 3, it's possible to update only the executable file:

Code: Select all

sudo wget https://raw.githubusercontent.com/rfmoz/tuptime/master/src/tuptime -O /usr/bin/tuptime
As you notice, between releases, Tuptime had also enhaced the output format.

Great that you finally found a workaround.
Locked

Return to “Beginner Questions”