solution for scheduled uploads - cron job?

2019-08-25 06:22发布

问题:

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.

回答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


回答2:

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