0

I'm trying to find the best solution for scheduling uploads to my server to specific directories.

  1. initially uploading the content
  2. pushing it live at the defined time

I've heard cron job recommended, but I've no idea how to use such a thing.

I'm trying to upload .html, .php, and .jpg files to multiple different directories all at the same future time.

I'm using Linux, cPanel, PHP. Typical LAMP stack + cPanel.

Any input is appreciated.

questy
  • 517
  • 2
  • 4
  • 14
  • Where do you upload your fine. As I may understand, Cron-task, means that you are on the beach and files being uploaded, so you have to define where are files come from? – SaidbakR Aug 11 '13 at 21:37

2 Answers2

1

cron is really easy. To edit the jobs type

crontab -e

This will give you a blank file with comments explaining its structure. You use numbers with wild cards to say when to run things, and then what to run. For example, from this page,

   # run five minutes after midnight, every day
   5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
   # run at 2:15pm on the first of every month -- output mailed to paul
   15 14 1 * *     $HOME/bin/monthly
   # run at 10 pm on weekdays, annoy Joe
   0 22 * * 1-5    mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
   23 0-23/2 * * * echo "run 23 minutes after midn, 2am,

cron will run the command regularly. If you just want it to run once, you need at. See here e.g.

at -f myscript.sh 2:00 july 13
doctorlove
  • 18,872
  • 2
  • 46
  • 62
  • Could you show me a working example of a one shot cron job? Like move 'x' content from one directory to other specified directories at a specified time/timestamp. Not a regular interval or anything. It's more in the sense of uploading specific time sensitive content automatically one time, rather than a maintenance thing. I'm trying to avoid having to stay up late to upload something for work on my birthday. – questy Aug 02 '13 at 09:15
  • @questy See edit. cron runs over and over, at runs once. There are many ways of specifying when- do "man at" – doctorlove Aug 02 '13 at 09:25
  • @doctorlove - How would you do a cron job once every two weeks on Sunday? Thanks in advance. – cosmoba Oct 24 '13 at 18:48
  • @cosmoba using a level of indirection: http://www.unix.com/aix/57530-crontab-job-sunday-two-week-interval.html or http://stackoverflow.com/questions/350047/how-to-instruct-cron-to-execute-a-job-every-second-week – doctorlove Oct 24 '13 at 19:01
0

You put this in your cron, this code will run your script for every 3 hours. And in your PHP script you can have there rename function which is moving the files in your target path.

* 3 * * * sudo -u www-data php5 /my/php/script.php
Drixson Oseña
  • 3,631
  • 3
  • 23
  • 36