I need to run a script when i login for first time in a day. I may reboot or shutdown and then power on during the day. But i do not want the job to run during those power ups. It should run only once per day.

3 Answers 3


use anacron:

Anacron can be used to execute commands periodically, with a frequency specified in days. Unlike cron(8), it does not assume that the machine is running continuously. Hence, it can be used on machines that aren't running 24 hours a day, to control daily, weekly, and monthly jobs that are usually controlled by cron.

read the whole manpage.

  • Typo in your first line: anacron, not anachron.
    – David Z
    Jul 12, 2010 at 7:07
  • I have a doubt. Can interactive programs be run using anacron?
    – Akilan
    Jul 12, 2010 at 12:07
  • define "interactive".
    – akira
    Jul 12, 2010 at 12:10
  • like for example gedit text editor.
    – Akilan
    Jul 13, 2010 at 5:08
  • so, "interactive" in the sense that it has a graphical user interface and is not waiting for some user input before it returns... that is still possible. you have to ensure that anacron (or the job anacron is starting) is launched after your X session is fired up. then you have to launch gedit with the DISPLAY environment set correctly and running under the correct user to launch gedit in the X session of the right user. but why would you want do this? search for the autostart mechanism of your desktop environment (kde, gnome, xyz), would be a better idea imho.
    – akira
    Jul 13, 2010 at 5:48

I wouldn't do that with cron - instead, configure the script to run whenever you log in, maybe by invoking it in ~/.bashrc or something like that. Then put some code at the beginning of the script to check the modification time on a marker file (you can choose any name and path you like for the marker file), and if it's been modified in the current day, make the script exit right away. After that, touch the marker file to update its modification time, and then the script can go on and do its business.


Call a script from your bash_profile. So it will start at each login.

Do required restrictions such as, run it at very first time and then log it in a file. Every run should read the log, to understand whether to proceed or exit.

Update: For opening a GUI application at every login anyway ( not only on first login, do use the touch marker technique for achieving that ) here is the tutorial: How To Launch Applications Automatically During Startup

  • thats essentially what @David Zaslavsky said.
    – akira
    Jul 13, 2010 at 8:46
  • David Zaslavsky also said the same thing. I can write such a script, but what i was looking for is an application which does this in a generic way. Anacron was very nice but only problem is that in my case i wanted it to run a gui app which expected some input from me. The reason to automate such a task is that i forget to do it daily. :p I'm willing to add such a functionality into gnome. Anyone know the package which executes autostart programs? (gnome-session-properties only adds or removes entries.)
    – Akilan
    Jul 14, 2010 at 6:44

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.