Just when I thought I was understanding cron jobs, I realize I'm still not understanding. I'm trying to set up a cron job through Dreamhost to ping a URL once an hour. This URL when visited performs a small(ish) query and updates the database.
A few examples I've tried which haven't seemed to of worked:
wget -O /dev/null http://www.domain.com/index.php?ACT=25&profile_id=1
and
wget -q http://www.domain.com/index.php?ACT=25&profile_id=1
The correct domain was inserted into the URL of course.
So, what am I missing? How could I execute a URL via a Cronjob?
One thing, are you escaping your url?
Try with:
wget -O /dev/null "http://www.domain.com/index.php?ACT=25&profile_id=1"
Having an ampersand in the URL usually leads to strange behaviour (process going background and ignoring the rest of the URL, etc).
I just had the same exact problem, and I found that actually two solutions work. One is as Victor Pimentel suggested: enclosing the url with " and the second option is to escape the & character in the cronjob like this: \&, so in your case the statement would look like this:
wget -q http://www.domain.com/index.php?ACT=25\&profile_id=1
or
wget -q "http://www.domain.com/index.php?ACT=25&profile_id=1"
Putting the following on the Dreamhost control panel\goodies\cron seems to work for me
wget -qO /dev/null http://domain/cron.php
links -dump http://Txx-S.com/php/test1.php
Worked much better than wget. It echoes the outputs of the php script into the email without all the junk that wget provides. Took awhile to get here, but it IS in the Dreamhost documentation. Don't need all the home/user stuff and the headache of placing all the php's under different users...
IMHO.
Pete
Related
I've tried every variation I can think of but can't seem to get my script to execute. I can hit it manually and it runs fine, but I'd prefer to have an outside server just hit it once per day. Is the trouble I'm having due to the presence of a query string?
My script URL looks like:
http://domain.com/index.php?g=main&reset=true
I've tried curl, wget, lynx, GET... all with no result whatsoever. What am I missing here?
Aha... knew it had to be something simple. Was missing quotes around the URL! Final working line in CPanel is:
wget -O - "http://domain.com/index.php?g=main&reset=true" >/dev/null 2>&1
You can just simply do like this in Cron Jobs
/usr/bin/curl --user-agent cPanel-Cron "http://example.com/index.php?g=main&reset=true"
I've never written a cron job cmd before in my life, and I want to make sure its right before I run it on my site so nothing messes up.
There is a json feed that my script autopost.php grabs and adds to my database. Usually I just point my browser to the file so it runs and updates the database but I hear cronjobs can do that automatically for me. Would this be correct?
wget -O http://www.domain.com/autopost.php
EDIT:
Okay with your help I got it working. However it only work when I added /dev/null after wget -O Why is that?
You're missing the run schedule part of the cron command. you need something like this:
* * * * * wget -O http://www.domain.com/autopost.php
That says "do a wget every minute. For the syntax, see:
http://www.adminschoice.com/crontab-quick-reference
-sure it can !!
follow this link and you will be able to program you job every time you want :
www.aodba.com
I tried a lot of methods but ended up with nothing in hand..My simple target is to reset a variable to zero at the end of the day.
i checked the location of php as "which php" and "whereis php"
which resulted into /usr/bin/php
here are some of things i tried..
/usr/local/bin/php -f /home/USERNAME/public_html/developer3/crons/filename.php
/usr/bin/php -f /home/USERNAME/public_html/developer3/crons/filename.php
php -q /home/USERNAME/public_html/developer3/crons/filaname.php
/usr/bin/wget -O http://subdomain.sitename.com/crons/filename.php
for quick results, i kept the timming as every minute to execute the code. i could successfully execute the code as
http://subdomain.sitename.com/crons/filename.php
please guide me.
If the path to php on your system is /usr/bin/php then the command you should be running with cron should be
/usr/bin/php /full/path/to/php/script.php
Is the script you're running designed to be invoked from the php-cli in that way? If it isn't and works correctly when you use a browser then you can use curl, if it's installed on your server
curl -A cron-job http://subdomain.sitename.com/crons/filename.php
It would likely be helpful in any event to configure the MAILTO variable (since you're using cPanel, it's just a text box on the appropriate page that you can fill in) so that you get an email with the output from your cron jobs. Having the output emailed to you will help you diagnose what's causing your script to not have the desired effect when it runs.
I need to write a cron job which hits a url once every day. Problem is that this url needs authentication. How can I authenticate and hit the url through a cron job?
Thanks
Then write a script, example from wget manual
# Log in to the server. This can be done only once.
wget --save-cookies cookies.txt \
--post-data 'user=foo&password=bar' \
http://server.com/auth.php
# Now grab the page or pages we care about.
wget --load-cookies cookies.txt \
-p http://server.com/interesting/article.php
then call this script from user cron or system cron.
If you want a helpful answer, you need to answer Adam's question: "Is this 'HTTP authenication' or a regular login?" (though I don't know what he means by "regular login").
Jasonw's answer is extremely unlikely to work.
Adam's answer of wget --http-user=foo --http-passwd=bar http://... is your best bet. In fact, given the "403" return code, I am willing to bet that it is the answer you need.
i have a function in a php web app that needs to get periodically called by a cron job. originally i just did a simple wget to the url to call the function and everything worked fine, but ever since we added user auth i am having trouble getting it to work.
if i manually execute these commands i can login, get the cookie and then access the correct url:
site=http://some.site/login/in/here
cookie=`wget --post-data 'username=testuser&password=testpassword' $site -q -S -O /dev/null 2>&1 | awk '/Set-Cookie/{print $2}' | awk 'NR==2{print}'`
wget -O /dev/null --header="Cookie: $cookie" http://some.site/call/this/function
but when executed as a script, either manually or through cron, it doesn't work.
i am new to shell scripting, any help would be appreciated
this is being run on ubuntu server 10.04
OK simple things first -
I assume the file begins with #!/bin/bash or something
You have chmodded the file +x
You're using unix 0x0d line endings
And you're not expecting to return any of the variables to the calling shell, I presume?
Failing this try teeing the output of each command to a log file.
In theory, the only difference from manually executing these and using a script would be the timing.
Try inserting a sleep 5 or so before the last command. Maybe the http server does some internal communication and that takes a while. Hard to say, because you didn't post the error you get.