Solved

cron updating file time but not writing to it

Posted on 2015-02-16
6
194 Views
Last Modified: 2015-02-16
I have a cron job that I want to grab a webpage and save it to a file. I've got it set up like this:

*/30 * * * *  wget http://www.mySite.com/test.php > /home/myOtherSite/public_html/test.txt

I expected that the html source of test.php would be written to test.txt... but that's not happening.

test.txt is having it's last updated time updated every 30 minutes, but nothing is being written to it. Permissions are set to 777.

Am I doing this wrong?

test.php is:

<?php
echo 'test, test, test';
?>

This is on a linux CentOS 6.
0
Comment
Question by:St_Aug_Beach_Bum
6 Comments
 
LVL 12

Expert Comment

by:Kent W
ID: 40613047
Rather than putting the command directly in the cron argument, create an executable script, then call the script with cron.

So */30 * * * * /path/to/my-wget-script.sh

Then, in /path/to/my-wget-script.sh, place your wget command.  Remember to make the script executable by the user you are running the cron job as.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
ID: 40613049
Maybe you wanted
wget -O /home/myOtherSite/public_html/test.txt
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 250 total points
ID: 40613113
You're using wget wrong. The wget program by itself will output status information about the download. You want to use the -O flag to specify the output file:

wget http://www.mySite.com/test.php -O /home/myOtherSite/public_html/test.txt
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40613114
And ozo already beat me to that answer. Oh well.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40613120
Also, some other things to consider:

1. If your cron job user isn't root, then make sure the user it is running as has access to execute wget. Generally speaking, try your command out on the command line first and if it works as expected there, THEN paste it into your cron.

2. Don't get into the habit of using 777 permissions. Is test.txt ever going to be executable? If not, use 6 instead of 7. If you only want your cron job to be the one writing to it, then use permissions 644 to allow your cron job to write to it and everyone else only gets read access. If not everyone needs access, consider 640 or even 600. Overall, using 777 is a really bad habit that can lead to serious security problems in the future. It takes the same amount of time to do it right.

3. If your cron job is running on the same server that is hosting www.mySite.com, then there's a slim chance you might run into a problem where the server doesn't realize that www.mySite.com should be accessed locally. If you still don't get your correct results after the -O switch, update your hosts file to put an entry in there for www.mySite.com that points to 127.0.0.1 and see if that works.
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 40613204
Wow, makes all the difference when it's done right :)

Thank you both very much, Ozo for the original answer, Gr8gonzo for the additional info and a clearer answer - really appreciate it,

Chris
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fine Tune your automatic Updates for Ubuntu / Debian
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question