5

I have a script that starts on desktop-session-start. The first person who logs in graphically after a boot will have this script called. I want it called once, not every time a person logs in. How do I make a script perform just once?

# one time script

start on desktop-session-start
stop on somebodystopme

script
...
end script
2
  • Once per user or once per system, ever? Feb 23, 2012 at 15:25
  • Actually, per boot. But, since it's a live remastered disk (no persistence), it will not know that.
    – bambuntu
    Feb 23, 2012 at 16:37

2 Answers 2

5

Use post-start script section instead of script section. It will leave the job as started/running state and it will not be re-run.

2
  • Great idea.. why didn't I think of that? ;)
    – SpamapS
    Feb 29, 2012 at 22:00
  • Thanks. That's what I was looking for. And, it will come in handy for one time initialization stuff. Very helpful advice.
    – bambuntu
    Mar 1, 2012 at 0:58
1
start on desktop-session-start
task

env FLAGFILE=/run/.my_script_has_run

pre-start script
  if [ -e $FLAGFILE ]; then
    stop
  fi
end script

script
  ...
  touch $FLAGFILE
end script

This assumes Ubuntu 11.10 or later. Use /var/run for earlier releases. /run is cleared after every reboot, so this will be run again on the next boot, but never again. It will stop normally after the touch statement, so there's no need for a 'stop on'.

1
  • I'm getting ready to move to 11, but I'm needing this for my 10.04 to finish up a project. I've been having to actually delete the contents of the script it calls in order to stop it. That just seems dirty.
    – bambuntu
    Feb 28, 2012 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .