[SOLVED] Perform action when computer is unlocked...

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
Hultan
Level 3
Level 3
Posts: 178
Joined: Mon Aug 27, 2018 10:58 am

[SOLVED] Perform action when computer is unlocked...

Post by Hultan »

I need a bash script or an application to run every time I log in to my computer, regardless of whether it is

* after a reboot
* after a suspend
* after a log out
* after a screen lock
* etc

Basically, every time I enter my password (successfully) I want this script (or application) to run. Is that possible and how?

[Edit] Alternatively, if anyone knows how to check if the computer is locked or unlocked, that would be useful too.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
djph
Level 7
Level 7
Posts: 1938
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Perform action when computer is unlocked...

Post by djph »

What does this script do? is it a per-user kind of thing, or is it sufficient for root to run it?
Hultan
Level 3
Level 3
Posts: 178
Joined: Mon Aug 27, 2018 10:58 am

Re: Perform action when computer is unlocked...

Post by Hultan »

What does this script do?
I didn't want to be too morbid so I left it out, but my mom died a week ago, and she was found about three days later, on friday. So, I started to think about what if something happened to me, well, I live alone and 5 hours away from my family, so I probably wouldn't be found until weeks, or months later, especially now when mom is dead. So, I need this to develop a solution that will send an email to my brothers to check up on me, if I have not logged in to my computer (or phone, but I will deal with that later) in 24 or 48 hours or so. Because, if I have not logged into my computer in 48 hours I am definitely dead :-)

My thinking is that I this script will open a webpage, that will update a date stored on a server. I could then use that same link from my phone, whenever I have time to fix that. And then I could write a program that checked this date every few hours, to detect when there was last activity, and then send an email if needed.
is it a per-user kind of thing, or is it sufficient for root to run it?
Definitely only my user account is of interest here...but I guess if it can be handled by the root account, I can live with that...

Basically, I just need to detect activity on my computer, that is definitely 100% made by a user and not a background process or something...
djph
Level 7
Level 7
Posts: 1938
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Perform action when computer is unlocked...

Post by djph »

I would personally skip the "automated" approach (sans "@reboot"), as it may get problematic (misfire, not fire, etc). Actually I would skip it on a personal machine in general -- what happens if your ISP goes down when something goes wrong, right?

Slightly more error tolerant (but it does cost money; and is a bit off-the-cuff):

1. get one of those $5 per month VPS's
2. set up a script that fires at login to (re-)set a scheduled job
3. If it's been 48 hours, since the scheduler's been reset, fire the panic notification (sms, email, whatever).

This assumes, of course, that the SMS / Email / etc. isn't going to be missed / rejected as spam (especially given the recent trends to nuke spam calls/texts/etc.). It may actually be more resilient to simply call/text every few days.
Hultan
Level 3
Level 3
Posts: 178
Joined: Mon Aug 27, 2018 10:58 am

Re: Perform action when computer is unlocked...

Post by Hultan »

So how do I do step 2 you mentioned? I want to at least experiment a little with the concept and see if I kind find a way that works for me.
djph
Level 7
Level 7
Posts: 1938
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Perform action when computer is unlocked...

Post by djph »

A script at login would be set up in your ~/.bash_profile (or ~/.bashrc) files.
Locked

Return to “Beginner Questions”