Magic2K2
11-28-2001, 04:13 PM
I need to do a cron that accesses a certain URL on my site at 5 AM each morning. Is there a way to do this?
I tried: lynx - dump URL
But, then I heard from my system administrator that lynx was using up all the resources.
Thanks, guys.
bobcares
11-28-2001, 04:24 PM
Hi!
I had posted a message some time back for cron jobs.
It uses wget..
I'm pasting it below for your convinience... :)
To create a cron for a user, log in as the user.
1) su $user
2) crontab -e
3) min hr date mon day /home/$user/$domain-www/path/to/script
where
min - minute (00 - 59)
hr - hour of day (00 - 23)
date - day of month (01 - 31)
mon - month of year (01 - 12)
day - day of week (00 - 06)
4) save changes
5) exit
However where you want a script in php to work you have to put in a little more.
Here's the instructions when php runs only as an apache module
Say you are user star and you want to run a php program(say http://www.star.com/exp.php) from cron and output the results to a file /home/star/phptest2
Telnet into the system as star
create a file (say /home/star/cronjob)
Add the folllowing lines to it
SHELL=/bin/bash
MAILTO=star@starinc.com
0 * * * * /usr/bin/wget -O/home/star/testphp2 http://www.starinc.com/exp.php
The above syntax means that at the start(0) of every hour(*) of every day(*) of every month(*) of every year(*), wget will run the exp.php and output the contents to testphp2. And when this runs, it will send a mail to star@starinc.com
Save the above file
now run crontab /home/star/cronjob
This will automatically add it to cron and execute it at the designated time
If you do not want to output the results anywhere simply omit
-O /home/star/testphp2
To view the contents of cron simply type crontab -l
to remove tasks from cron simply type crontab -r
Say you are user root and you want to run a system critical php program(say http://www.starinc.com/exp.php) every hour from cron and output the results to a file /home/star/phptest2 here's what you do
ssh into the system as root
create a file say( /etc/cron.hourly/phpcron)
Add the folllowing lines to it
#!/bin/sh
/usr/bin/wget -O/home/star/testphp2 http://www.starinc.com/exp.php
save and chmod to 755
Here cron automatically reads /etc/crontab , detects all scripts in /etc/cron.hourly (in our case phpcron) )and executes them
For hourly , daily, weekly and monthly, store your scripts in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly respectively
I hope this helps.
Have a great day
Regards
Amar
Magic2K2
11-28-2001, 06:40 PM
In my Control Panel, it already has cron jobs set up so I don't need to telnet in. It asks for the time to run it, which I understand, and then what command to run. I'd like to execute the URL and really do nothing with the output, but I guess I could e-mail it to myself.
Would this work:
/usr/bin/wget URL
or do I need the path to output it to before URL
/usr/bin/wget -OUTPUT URL
bitserve
11-28-2001, 07:59 PM
Hey amar, nice post. I knew you'd eventually post something worthwhile. I wasn't about to go into explaining it, but you took the time and did a decent job of explaining cron.
If only magick2k would have provided the aditional information sooner.
magick2k, you'll need to install something that can connect to the webserver.
You might try installing "lynx", then you could make the command:
lynx -dump URL >/dev/null 2>&1
Magic2K2
11-29-2001, 12:10 AM
I can't install on the server. I'm just a client. Will the wget thing still work? I tried lynx before and, as I said, they said I was using too many resources, but I don't know why.
bobcares
11-29-2001, 09:13 AM
I'm sorry guys I missed this post somehow... :(
Are you using a cpanel control panel.
Have a great day :)
regards
amar
JustinK
12-02-2001, 08:13 PM
If it's a script you need to run try putting the following in the command textbox (the big one):
For Perl/CGI:
perl /path/to/script/script.ext
or
For PHP:
php /path/to/script/script.ext
Dunno if either of those will do any good for you, but it's what I use for that stuff. Hopefully it's what you're looking for. If not, sorry I wasted your reading time. :)