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 would like to append current date to text file every morning at 7am. if the computer is turned off I would like it to be executed after its turned on.

share|improve this question
up vote 2 down vote accepted


date +%Y-%m-%d >> /path/to/file

Save that in a file under /etc/cron.daily/ and make it executable. It's important that the file does not have an extension.

The files in /etc/cron.daily/ are run daily by anacron in the morning (not exactly 7am, but around then) or during boot if it hasn't already been run that day.

share|improve this answer

setup a cron job with the following bash script

touch lastexecution
if [ '`date +"%Y%m%d"`' != '`cat lastexecution`' ]; then
  echo `date +"%Y%m%d"`>>datefile
  echo `date +"%Y%m%d"`>lastexecution

execute this script at bootup and at 7 o'clock. To keep things simple, this script also writes the current date if the computer boots up before 7 o'clock, but only once a day. It creates two files: lastexecution which holds the date of the last time the batch file wrote the date into the file and datefile, where it appends the current date.

share|improve this answer

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.