Solved

cron updating file time but not writing to it

Posted on 2015-02-16
6
180 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 34

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 34

Expert Comment

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

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now