Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 10091  / 1 Year ago, mon, january 23, 2023, 1:56:48

I have an bash script that runs on a every minute cron. It checks to see if a necessary program is running and starts it if it is not. Occasionally it will run before the user has actually autologged in. I want to prevent that from happening.



What I think I'd like to do is to put a check in the check the computer's uptime and see if it'd been on for 5 minutes so that auto login had a chance to finish before the program gets started. I'm fairly new to bash and parsing what I get from "uptime" to where I could use it for comparison seems out of my reach.



Can anyone help? Perhaps there is a better solution. I'm stuck.


More From » bash

 Answers
6

A bash script/cron job is the wrong solution for the problem you are trying to solve. Actually, scratch that -- two bash scripts/cron jobs are the wrong solution for your problem. ;)



The problem you are trying to solve is, "ensure a task starts running after a user has logged in, and ensure it stays running". This is a job for upstart.



The following should do what you want, and it goes into /etc/init/. Name the file something like user-session-job.conf.



description "Keep my very important program running"

start on desktop-session-start
stop on desktop-shutdown

respawn

script
/path/to/my/very/important/program
end script


Please see the upstart cookbook for lots more help:
http://upstart.ubuntu.com/cookbook/


[#42198] Monday, January 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pheter

Total Points: 223
Total Questions: 111
Total Answers: 119

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
pheter questions
Mon, Jun 21, 21, 07:35, 3 Years ago
Tue, Jul 5, 22, 22:50, 2 Years ago
Sat, Nov 27, 21, 17:50, 2 Years ago
;