Cannot get wget command to ouput reponse results to a file when run from perl script

Viewed 44

I am running a perl script via cron. I've got this line in the script:

`wget --no-cache --output-document=${dir}index.html localhost > /dev/null 2>&1`;

This works just fine. The contents of the file are saved to the disk.

But I cannot get seem to get this to work:

`wget -S --output-document=${dir}status.txt --spider -q -t 1 "example.com" > /dev/null 2>&1`;

The file is created, but it is empty. In trying other things, I discovered that this works from the command line:

wget -S --spider -q -t 1 "example.com" 1&>status.txt;

However, when I drop it into the perl file, the file is again empty. I'm not sure what is going on. The cron job is running as the same user I'm using on the command line.

1 Answers

When I have issues running a system command from a Perl script, it can be helpful to print the command string to STDOUT so that you can see if Perl is interpolating any part of it unintentionally. I don't know if you are running your Perl scripts with "use strict" but it should pick this up for you.

Also within the cron file, pipe the output of the script to a debug file to see if there are any issues it is encountering. Include the "2>&1" statement at the end so it catches errors as well.

Related