The command you’re using:
bashgdbus monitor -y -d org.freedesktop.login1 | grep -m 1 LockedHint
hangs because of how gdbus monitor and grep interact:
gdbus monitor continuously streams D-Bus signals in real-time and does not exit on its own. It waits for new events indefinitely.grep -m 1 will exit after the first match, but only if the input stream closes. Since gdbus monitor keeps running and the pipe remains open, grep cannot know if more input is coming. Thus, it waits for the stream to end, which never happens.To make the command exit after the first match, you need to ensure that gdbus monitor exits after the relevant event. You can do this by using a tool like stdbuf or timeout, or by using a more sophisticated approach with awk or sed to close the stream after the first match.
timeout:bashtimeout 10 gdbus monitor -y -d org.freedesktop.login1 | grep -m 1 LockedHint
This will force gdbus monitor to exit after 10 seconds, allowing grep to finish.
awk:bashgdbus monitor -y -d org.freedesktop.login1 | awk '/LockedHint/ {print; exit}'
This will print the first line containing "LockedHint" and then exit, closing the pipe.
stdbuf (if buffering is an issue):bashstdbuf -oL gdbus monitor -y -d org.freedesktop.login1 | grep -m 1 LockedHint
This ensures line buffering, but the command may still hang unless the stream is closed.
The hang is due to gdbus monitor not terminating, so grep keeps waiting. Use timeout, awk, or another method to force the stream to close after the first match.
This Chat is read-only. Login to resume chatting.