Web Hosting Talk







View Full Version : Cron to help update file?


mealto
04-19-2007, 06:02 PM
We want to update our feed at 5am everyday. Is it possible to use Cron inside Cpanel to execute a function where 1 file can be used to overwrite another on the server?

Example:
- feed.xml (real feed)
- feed-update.xml (updated feed from the night before but we do not want to publish this yet)
- at 5am, overwrite feed.xml file with feed-update.xml file so that it looks like we are manually publishing our feed.xml at 5am?

Any help would be greatly appreciated.

xgoth3
04-20-2007, 05:38 PM
First you will need to know the entire file path on the server, i.e.: /home/user/www/feed.xml

If your CPanel account has Shell enabled, you can do this with a simple Shell file:

#!/bin/sh

PATH = /home/user/www

mv $PATH/feed-update.xml $PATH/feed.xml


Then upload the file, and add it to run at 5 am on Cron Manager on CPanel.

If you don't have shell access, you can do the same with a Perl or PHP file.

Regards

mealto
04-20-2007, 06:31 PM
I see. We have shell access but not sure how to set this up via this method. Can you give more detailed instructions for creating, saving and uploading the file via SSH?

Maybe a better method is to run a php file. Do you happen to have a PHP tutorial on how we can run the same funcion that you described but in php?

ThatScriptGuy
04-20-2007, 08:09 PM
He just told you exactly how to do it. Create a file, called, perhaps, feed.sh. The contents of which should be what was posted above. Then run that script every morning at 5AM and it will overwrite the old with the new.

mealto
04-20-2007, 09:30 PM
Again, thanks for the patience. How does one create a file? Would I use notepad and then upload it to the web server then call it in the CRON? Anymore info would be greatly appreciated. Not so sure how to use SSH commands.

ThatScriptGuy
04-20-2007, 09:32 PM
Log in to SSH. Make a directory, called, say, 'bash'

mkdir bash

Then, go into that directory

cd bash

Then create a new file, called, maybe, cron.sh

vi cron.sh

Now hit 'i' on your keyboard to go into Insert mode.
Then type the following:


#!/bin/sh

PATH = /home/user/www

mv $PATH/feed-update.xml $PATH/feed.xml

Then hit the escape button on your keyboard to enter command mode.
Now type :wq to save the file and exit the editor.

Now just make cron run that script.
Kevin