Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

end script
share|improve this question
Once per user or once per system, ever? – Lakritsbollar Feb 23 '12 at 15:25
Actually, per boot. But, since it's a live remastered disk (no persistence), it will not know that. – bambuntu Feb 23 '12 at 16:37
up vote 4 down vote accepted

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.

share|improve this answer
Great idea.. why didn't I think of that? ;) – SpamapS Feb 29 '12 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 '12 at 0:58
start on desktop-session-start

env FLAGFILE=/run/.my_script_has_run

pre-start script
  if [ -e $FLAGFILE ]; then
end 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'.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.