[Tutor] Desktop Notifications on Linux

Cameron Simpson cs at zip.com.au
Thu Jun 29 19:28:12 EDT 2017


On 10Apr2014 17:04, Dharmit Shah <dharmit.dev at gmail.com> wrote:
>On Thu, Apr 10, 2014 at 2:30 PM, Peter Otten <__peter__ at web.de> wrote:
>> Dharmit Shah wrote:
>>> I am trying to create a script that will go through the
>>> /var/log/secure file on a Linux system and provide desktop
>>> notifications for failed login attempts.
[...]
>>> For readability purposes, I have provided pastebin links. Let me know
>>> if this is not the correct way.

We like the code inline. If it is big, maybe tack it onto the bottom of the 
message. That way people can (a) read your message when offline, as I sometimes 
do on a train (the email is already downloaded to my laptop) and (b) the full 
context is present in the mail archives so that things make sense when perusing 
them.

Peter Otten said:
>> Maybe you are running the code as a user that has no "desktop"? [...]

You again:
>That does ring some bells. I am logged into my F20 system as non-root
>user but since reading /var/log/secure file requires superuser
>privileges, I am running it as sudo:
>
>  sudo python secure.py
>
>That probably explains the issue I am facing. I will add the user to
>the root group and see if it helps.

As a matter of good practice, try to run as little as possible as root. Minimum 
priviledge means minimum scope for mistakes to do damage.

If the secure file has a group granting only read access, your group additional 
is a reasonable thing to do.

Failing that, consider something like this:

  sudo tail -F /var/log/secure | python secure.py

and have secure.py just read from standard input. This is that advantage that 
(a) the only root thing is the tail command, which just reads and (b) your 
program can produce alerts in real time as they come in from the tail, without 
having to write painful "tail"-like logic within the program.

Cheers,
Cameron Simpson <cs at zip.com.au>


More information about the Tutor mailing list