The `who` command.... How can I see the result in NR?

Maybe I'm being paranoid.... :wink:

I'm wanting to run the command who now and the and get the result back as something NR can handle.

pi@TimePi:~ $ who
pi       tty1         2024-06-01 22:32
pi       tty7         2024-06-01 22:32 (:0)
pi       pts/1        2024-09-13 14:48 (192.168.17.6)
pi@TimePi:~ $ 

So that would ....... give me...... 3.
SOMETHING that if more people log in, it increases.

Thoughts?

who | wc -l

simple flow with a who | wc -l and a switch ...

[{"id":"ef091c04beb228ca","type":"exec","z":"37731ca11bbd1b42","command":"who | wc -l","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":626,"y":360,"wires":[["974751273bbe2ff3"],[],[]]},{"id":"b5caf2dcc5d99384","type":"inject","z":"37731ca11bbd1b42","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":385,"y":360,"wires":[["ef091c04beb228ca"]]},{"id":"974751273bbe2ff3","type":"switch","z":"37731ca11bbd1b42","name":"","property":"$number($parseInteger($trim($$.payload), '#0'))","propertyType":"jsonata","rules":[{"t":"gt","v":"3","vt":"num"},{"t":"gt","v":"2","vt":"num"},{"t":"gt","v":"1","vt":"num"},{"t":"gt","v":"0","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":5,"x":804,"y":347,"wires":[["fab6c974689f21df"],["f9891084d34f65b0"],["107bf6521d8d7f6e"],["129a7599f3ef1a04"],["eec31dbe9a35fcde"]]},{"id":"fab6c974689f21df","type":"debug","z":"37731ca11bbd1b42","name":"> 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":996,"y":250,"wires":[]},{"id":"f9891084d34f65b0","type":"debug","z":"37731ca11bbd1b42","name":"> 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":996,"y":298,"wires":[]},{"id":"107bf6521d8d7f6e","type":"debug","z":"37731ca11bbd1b42","name":"> 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":996,"y":346,"wires":[]},{"id":"129a7599f3ef1a04","type":"debug","z":"37731ca11bbd1b42","name":"> 0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":996,"y":394,"wires":[]},{"id":"eec31dbe9a35fcde","type":"debug","z":"37731ca11bbd1b42","name":"== 0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":998,"y":439,"wires":[]}]

Ok, thanks.

I'm slightly confused though.

pi@BedPi:~ $ who
pi       tty1         2023-10-03 06:43
pi       tty7         2023-10-03 06:43 (:0)
pi       pts/0        2024-09-13 17:26 (192.168.17.6)
pi@BedPi:~ $ 
 

When I run the flow on that machine I get

Ummmm...

HANG ON!

Ok, edited the CLI paste.
(Sucks sometimes when you are remoted into a few machines.)

So - sorry - the problem/confusion remains.
(Original paste was from a different machine)

Ah!
Ok, so if I am not ssh into the machine, it is 2, and if I ssh in I get 3.

SORRY!

the flow is differentiating between count of users - so the debug you're seeing is coming from the debug labeled "> 1", i.e. you have two users and that's greater than one but less than two!

basically you can remove the switch but it does give you a JSONata expression to convert the string "2\n" to a number 2 - that might be useful.

1 Like

Oh, sorry, a quickie which I did just realise is problematic with how that works.

So, with no remote login (by me) the number I get is the 2.

But I'm wanting to know if......

Thinking as I am typing

Ok, so I then join all the OTHER outputs from the switch node that are NOT wanted.

Then if any of them are sent: I am notified?

Yes?

Yeah, sorry. That was my mistake.

So you want to know "who is logged into my raspberry who isn't me"?

That's isn't easy if you have one user, i.e. pi. I guess using the ip on the who output and filtering on that might help ....

Not really. Just to get a notification of the number goes above the normal one.

I'm testing the idea I just said.

Ok let me rephrase my assumption: "who is logged into my raspberry who isn't normal"? :wink:

Yeah... Sorry I didn't mean to be difficult.

Though the idea I had - posted - does seem to be a good one.

ok so you want the notify logic on the outputs of the switch that is greater than 1 i.e. '>1', '>2' and '>3' - the top three debug nodes.

Not at all :slight_smile: All good! I tend to read only half the questions, so my answers tend to be misguided!

This seems to work.

but you have also connected to '== 0' and '> 0' that will also send a notification when no one is logged in or just one ...

Me being anal.

But I though of that way after asking the better question.

1 Like

I'll accept your idea - with my mod - as the answer.

Thanks.

Now I've got a lot of problems with queued MQTT messages.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.