Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron-job creates unwanted files 1

Status
Not open for further replies.

mpartarrieu

Programmer
Nov 21, 2006
34
ES

Hi,

I created a php script that send a newsletter on batches of 30 emails per hour. It uses a cron-job to send emails, and everything works fine except that the cron-job creates blank files in the root directory of the server everytime it runs the script.

I tried to stop this by setting crontab as follows:

Code:
30 * * * * wget -q <absolute_url_of_email_sender_script>

...but the quiet param hasn't stop the creation of files. Any ideas of how to stop this??

Thanks in advance.

 
Without taking apart your script to find out if it's broken or doing unintended things, you could start with appending:

Code:
 2>&1 > /dev/null

to the end of your posted entry in crontab.

This redirects STDERR and STDOUT to /dev/null.
This eliminates any output or errors that would have gone to the screen. However, if you script is writing files on its own, this won't help



D.E.R. Management - IT Project Management Consulting
 

thedaver,

Thanks for the quick response. I tested the script calling it directly and it does exactly what it's supposed to do: send the newsletter. I actually use /dev/null tag to stop it from sending emails to me after each cron-job is executed.

My problem is that crontab writes blank files with the same name as the script it's running (the email_sender_script name), with no content at all. It seems that wget executes the email_sender script and then saves whatever it returns in the root directory of the server. As the email_sender_script returns a blank page, wget saves a blank file.

Any ideas??

 
you may have a user permissions error in your crontab entry. or you may have a command missing from the cron user's path that is needed to provide the script with full, correct functionality.

You can specify a username (e.g. 'root') before your 'wget' item in the crontab.

You should also use absolute paths in your scripting.

D.E.R. Management - IT Project Management Consulting
 
isn't this the default behaviour for wget? it is 'getting' the output the remote php file.

you can suppress the screen output using the -o switch.

instead of using wget why don't you fire off a php script? using php you could fork multiple processes to speed up the sending?

If the email sending php script is remote the first part of the approach will still work

Code:
<?php
//fire off remote php script
$url = "[URL unfurl="true"]http://www.example.com/path/to/php/script.php";[/URL]
get_headers($url);
?>
 

Thanks jpadie and thedaver for your insights. I already tried to stop this behaviour using the -o switch, but it didn't work and emails just stop being sent.

I'm using wget because it's the only way crontab actually executes the php script correctly, so far. So right now I have the script running correctly and doing exactly what I want. The only thing that bothers me is that wget writes a file with the outcome of the newsletter sender script, which is a blank page. Accordingly, wget saves a blank file.

I I'm now saving these files on a directory using the -P param and so far it works for me, only that it's creating as many files as times crontab runs (that's 24 per day). What I need now is to order wget to save the file with a given name (say outputfile.txt) and, if this file already exists, to overwrite it. If yu know any way I can do this, I'll be more than grateful.

Thanks again and any help in this sense will be appreciated.

 
the -o switch just suppresses the error log from sending you emails.

you will not be able to avoid files being created when you use the wget. that is the point of the wget utility. you can force the file name by adding the name at the end of the wget line

Code:
wget --input-file="[URL unfurl="true"]http://someremotedomain.com/path/to/script.php"[/URL] --output-file="./logfile.txt" --output-document="./output.txt"

but, there is no reason why you can't use php with crontab. if the below does not work try putting an absolute path to the php binary.
Code:
php < /path/to/php/script.php
 

I'm unable to usu php with crontab, but it really doesn't matter because crontab is doing exactly what I want it to do. Moreover, I change the php script and now it saves information about sent emails on the output file.

Thanks jpadie; your approach is working just fine.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top