killrwhale
03-18-2010, 08:08 PM
Hello,
I have a php script that runs on my webhost, but it gets stopped by my webhost every 2-3 days. I have to login using Putty and execute the php commands on my script to run it again. Is it possible to set something up so the php commands get executed nightly automatically?
Thank You
weboutloud-Chris
03-18-2010, 08:13 PM
Absolutely, check out cron:
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
That should be enough to get you started.. let us know if you need anything.
killrwhale
03-18-2010, 08:23 PM
Absolutely, check out cron:
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
That should be enough to get you started.. let us know if you need anything.
Awesome, Thank You.
Can I use this with just SSH access though? Since I am using a webhost?
Thanks
ThatScriptGuy
03-18-2010, 09:38 PM
You can usually set up cron jobs through your webhost's control panel.
weboutloud-Chris
03-18-2010, 10:06 PM
Awesome, Thank You.
Can I use this with just SSH access though? Since I am using a webhost?
Thanks
Yep, and just like ThatScriptGuy said, you can usually set them up via your hosts control panel as well.
If they use cPanel, see: http://www.siteground.com/tutorials/cpanel/cron_jobs.htm
killrwhale
03-19-2010, 04:49 PM
Yep, and just like ThatScriptGuy said, you can usually set them up via your hosts control panel as well.
If they use cPanel, see: http://www.siteground.com/tutorials/cpanel/cron_jobs.htm
Sweet, I do see it in my webhosting CPanel. But I was wondering how do I make sure cron jobs executes the command in the right directory?
Basically, when I want to activate my script, I run three commands in Putty to do so:
cd public_html/script
nohup php script.php &
php script.php
After that, my script is running fine. How would I setup cron job to execute those commands?
Thank You
ThatScriptGuy
03-19-2010, 05:38 PM
You would just set up the cron job to run
nohup php /home/YOUR_USERNAME/public_html/script/script.php
Assuming your public_html directory is in /home/YOUR_USERNAME
killrwhale
03-19-2010, 06:09 PM
You would just set up the cron job to run
nohup php /home/YOUR_USERNAME/public_html/script/script.php
Assuming your public_html directory is in /home/YOUR_USERNAME
AWESOME! Just tested it, worked perfect.
Thank you guys!
weboutloud-Chris
03-19-2010, 08:32 PM
AWESOME! Just tested it, worked perfect.
Thank you guys!
Not a problem, always feels good to help. :)
mattle
03-19-2010, 10:51 PM
cd public_html/script
Just a quick note, cron doesn't necessarily run in the environment you'd expect it to. It's generally good practice to provide full paths for everything:
10 10 * * * /bin/ls /home/me/public_html/uploads | /bin/mail -s ...
jadursupport
03-20-2010, 06:50 PM
You would just set up the cron job to run
nohup php /home/YOUR_USERNAME/public_html/script/script.php
Assuming your public_html directory is in /home/YOUR_USERNAME
Yup Thats the good one
nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out which carry out what you want.