Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
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
add comment

2 Answers

up vote 3 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
add comment
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'.

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
add comment

Your Answer

 
discard

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.