Get Email Alerts of Downloads’ Progress in Linux

In this article I will show you how to get free email alerts of progress of downloads going at your home. It comes handy when you are away from your desktop.

Yesterday was a family get-together, which meant I had to be out of the house most of the day. But the thing was that I had a download currently running, ArtistX DVD iso (yes, review and screenshot coming soon). It weighted over 4 gBs which meant over 4 days of constant download in my slow connection. So, something had to be done which notified me about the download progress and shuts down my PC if the connection is broken/download is done. I chose email as the notification because I could access it all the time from my cell phone.So basically, what I did is installed a console based email client that emails me the file details, and set up a cron job that executes the program on a regular interval of time.

Here we go.

Using your favorite package manager, install mutt. I chose mutt against clients such as sendmail and others because its easy to configure and use. If you are on Arch Linux, you can use this command.

sudo pacman -S mutt

Once installed, you need to set up IMAP and SMTP so that it can send and receive emails. I used Gmail with following configuration. If you use other service, inquire about it settings and set it up.

set from = "[email protected]"
set realname = "Your Name"
set imap_user = "[email protected]"
set imap_pass = "your password"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = "smtp://[email protected]:587/"
set smtp_pass = "your password"
 

This is the minimum configuration to have mutt working. Save the file as .muttrc in your home folder. Also create two folders, .mutt and .mutt/cache in your home folder.

mkdir .mutt
mkdir .mutt/cache

 To check mutt is working or not, fire it up by typing mutt in the terminal. If it does and you are able to access your emails, congrats, you have successfully set up the first part of this setup.

Now remember that you have to do the downloads in a single folder where no other files reside. So create an empty folder specially for downloads you are going to do while you are away. I used wget because its utterly relaible, you can use any download client you want. For the list of best download managers in Linux, click here.

The format of command line for mutt to send mail is something like this

mutt -s "subject" [email protected] < body.txt

We need to write the script now, the first thing that we need to do is to write the downloading file details in a file that will include its size. Go to the empty folder you created and first create the script file, say tasks.sh. In it, write

ls -l downloadingFileName > message.txt

This will write the file details including size, owner and read-write access to the file “message.txt” which will become the body of our email. By seeing the size attribute, you will be able to determine how much of your file has been downloaded.

Now in the next line of the script, we will invoke mutt and send the message.txt file to your email address. The whole script now looks something lie this :-

ls -l downloadingFileName >message.txt
mutt -s "file progress" [email protected]

Save this file as tasks.sh in the same folder where file is being downloaded. Make it executable using

chmod +x tasks.sh

Now we will setup the cron job to email us at regular intervals. Open terminal and type:

crontab -e

This will open your cron file in an editor, possibly vi. Type the following to send you the file progress by email every hour.

@hourly /path/to/task/file/tasks.sh

Replace the path with the path where you saved the tasks.sh file. Thats done. You will receive email alerts no matter wherever you are about the download progress going at your home. If you want to get alerted every 10 minutes of the download progress, you can do something like this

10 * * * * /path/to/task/file/tasks.sh

Replace 10 with your preferred number of minutes.

In the next few posts, I will tell you about how to get free SMS alerts of the progress of download (this will come handy if you are on an expensive data plan), a perl script that will send the percentage of file downloaded and a trick to shutdown your PC automatically when download is done. So it will be the right time to subscribe to our RSS feeds so that you get updates of new posts.

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.