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
Solved

cron updating file time but not writing to it

Posted on 2015-02-16
6
190 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Custom Wordpress Loop 22 38
PHP Mail error 3 27
Undefined variable problem 5 23
Linux MD5 Hash 7 41
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é.
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…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

837 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