?
Solved

cron updating file time but not writing to it

Posted on 2015-02-16
6
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 total points
ID: 40613049
Maybe you wanted
wget -O /home/myOtherSite/public_html/test.txt
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 1000 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

764 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