Best way to schedule a task that is be excuted years later

What is the best way to schedule a task that is be executed years later? Like execute a script after 4 years.

Is cron the best method for that?

Any other option other than cron/at ? :confused:

$ date -d "+4 years " +%s
1390194960
$ date +%s
1263964545

So add one if-then command in your script, such as: (not tested)

if [ `date +%s` > 1390194960 ]; then 
#  Your script here
fi

You can run the script every day by cronjob.

You can use at, with either of these syntaxes:

at 201401201200
at +4 years

Note that the first one uses a 24 hour format.

Yes, cron / at is a best option.

But it depends, You have to be sure that, nobody will edit your cron entry ( say, two or three admins then somebody may ? ).

But in case of at, you have to remove it by finding the at job id. So you might find that better suited for you, where as in cron all the CRON jobs will be given for edit with 'crontab -e'.

To remove all the 'at' jobs :

atrm $(atq|cut -f1)

Will the task set using at get reset on reboot ?

YES ! :slight_smile:
Another advantage is that if the computer is down at the specified time, at will run the job at bootub.

definitely not.

Both cron & at jobs will sustain across reboots.