views:

209

answers:

2

I am required to write a script that would download a file (based on a provided url to that file) using wget and then pipe the result to the mail command so that it can be mailed to a provided email address. This will be used in a php based project.

"Piping the result" preferably would be a built link to the file on the server, so that the recipient of the mail could just click the link and get the file locally.

Anyone have experience in this area of combining commands they would share?

A: 

Use the PHP binding for CURL

kazanaki
A: 

Pseudocode, might even work directly, save it to a file and call it with 2 parameters, first one is the url of the remote file you wish to download, second is the email where to send the notification.

LOCALPATH variable should be a directory which is accessible from www and LOCALURL should match that location.

#!/bin/bash
URL=$1
FILE=`basename $URL`
EMAIL=$2
LOCALURL=http://yourdomain.com/files
LOCALPATH=/var/www/html/files
cd $LOCALPATH
wget $URL
cat<<END|mail -s "New file available" ${EMAIL}
Hello, 

   your new file can be downloaded now from:

   ${LOCALURL}/${FILE}

Thanks!
END
rasjani
Thank you rasjani, this script as is work perfectly! :)
logansama