Solved

cron updating file time but not writing to it

Posted on 2015-02-16
6
206 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 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

688 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