2

I need to run a script ONCE the first time the system connects to the internet. So I use post-up in my interface to run the script.

However, I only want to run the script once per boot. So if the interface were to be brought down and up again, I don't want my script to run again.

What can I do?

  • You have to put your script into an script in /etc/init.d Then you have to link it to /etc/rc6.d and enable it. not disable. – PersianGulf Apr 29 '15 at 22:21
  • Which init system do you use? systemd, sysvinit, or even anything else? If you do not know, you could tell us what file /bin/init and cat /proc/cmdline output. – XZS Apr 29 '15 at 22:47
  • What distribution are you using? – Gilles Apr 29 '15 at 23:42
2

In order to make your script only run once per boot you can do one of the following:

  • assuming you have cron: Create a cron job with time specification @reboot (check man 5 crontab) to run your script. The script then has to wait for devices or connection and such things itself.
  • assuming you run the script in some other way: Your script can create a empty file in a place that will be deleted on reboot. Some temp directory might be suitable. You have to check that the marker file will only (but always) be deleted on reboot. You can also create a counter part script that will be executed on shutdown which will delete the file again. The problem is that the second script might not execute in some error conditions (hard reset). Your script can then check if the file exists and exit early if it already ran.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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