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
Jorge Castro
  • 73,907
bambuntu
  • 1,001

2 Answers2

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.

Tuminoid
  • 3,932
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'.

SpamapS
  • 20,150
  • 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 '12 at 14:46