2

Basically I want to create a directory at some fixed time and after exactly five minutes, I want to create a text file in that directory.

I tried this code but it didn't work

6 13 * * * /usr/bin/mkdir /qwerty /usr/bin/touch file1
  • 3
    You should use at instead of cron for this. – muru Feb 7 '17 at 9:25
2

Here is the command you asked cron to run:

/usr/bin/mkdir /qwerty /usr/bin/touch file1

This calls mkdir with tree parameters: /qwerty, /usr/bin/touch, and file1. So, mkdir will attempt to create those as directories. You probably meant to run those as two separate commands:

 6 13 * * * /usr/bin/mkdir /qwerty
11 13 * * * /usr/bin/touch /qwerty/file1

Another style would do this as a one-liner:

6 13 * * * /usr/bin/mkdir /qwerty && sleep 5m && /usr/bin/touch /qwerty/file1

Note that using cron for one-off jobs is strange; as mentioned in a comment to your question, an at job would make more sense.

Also, this will still fail unless the user is allowed to create directories under /.

0
$ echo "mkdir test && sleep 300 && touch test/file" | at 06:13

This will schedule the echoed command to run at 06:13. If 06:13 has already passed, it will be run at that time tomorrow.

Any output from the job will bu mailed to you.

The the at manual for the different ways you may specify the time.

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.