-2

I need to create a cron job that runs every hour.

This cron job should create two files, each 2GB, one should be created from /dev/urandom and the other one from /dev/zero and should be written to a specific filesystem/directory.

How would I do this?

3
  • 1
    Since you know you need dd and Cron… What have you already tried?
    – slhck
    Jan 2, 2014 at 11:46
  • 2
    not to mention, what's the point of recreating a file of zeros every hour? Or for that matter, for stale psudorandom numbers - something best served hot and fresh? What are you trying to do?
    – Journeyman Geek
    Jan 2, 2014 at 12:23
  • @JourneymanGeek the purpose of this is to test the Disk I/O
    – user286205
    Jan 2, 2014 at 14:49

2 Answers 2

1

You can create these files with dd command like below:

dd if=/dev/zero of=/tmp/ZeroFile count=10000 bs=200000

dd if=/dev/urandom of=/tmp/UrandomFile count=10000 bs=200000

and for scheduling this jobs with cron you have to put this command in your cronjob:

  1. crontab -e
  2. write it: 0 */2 * * * /path/to/your/command
2
  • thanks Sepahrad! what exactly does the */2 bit in the crontab do? also is it ok to insert the whole dd-command directly in the crontab? e.g 0 */2 * * * dd if=/dev/zero of=/new/ZeroFile count=10000 bs=200000 0 */2 * * * dd if=/dev/urandom of=/new/UrandomFile count=10000 bs=200000
    – user286205
    Jan 2, 2014 at 14:47
  • Your welcome, * means all the time and */2 means every 2hours.. Put them in separated line... It must be work... If not you have to set PATH variable for cron or write absolute path of the dd command. Jan 2, 2014 at 15:54
0

Edit the user crontab

crontab -e

Then add the following lines

0 * * * * dd if=/dev/random of=/tmp/myfile1.dat bs=$(( 1024 * 1024 * 1024 )) count=2
0 * * * * dd if=/dev/zero   of=/tmp/myfile2.dat bs=$(( 1024 * 1024 * 1024 )) count=2

Or edit /etc/crontab and substitute user_to_run_as with the user you want to run the command as

0 * * * * user_to_run_as dd if=/dev/random of=/tmp/myfile1.dat bs=$(( 1024 * 1024 * 1024 )) count=2
0 * * * * user_to_run_as dd if=/dev/zero   of=/tmp/myfile2.dat bs=$(( 1024 * 1024 * 1024 )) count=2

I tried it out and using /dev/random doesn't give you an exact file size. "Why does dd from /dev/random give different file sizes?" seems to give the explanation for this

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .