LJ Archive

Auto-Download Linux Journal Each Month

There's an old saying, "anything worth doing, is worth automating"—or something like that. Downloading and reading Linux Journal always has been worth doing, and now you can automate it with our new autolj script, which you can get here.

Follow these few simple steps, and you can be downloading the PDF (or the .epub or the .mobi file) with the greatest of ease each month:

1) First download the script and save it somewhere; ~/bin is a good choice. You can name it whatever you like; it doesn't need to be called autolj.sh.

2) Open a terminal/shell and execute the following commands:


$ chmod +x ~/bin/autolj.sh
$ ~/bin/autolj.sh --init
Enter the email and zip/postal code associated
with your Linux Journal subscription
EMail: you@example.com    # Enter your email address
Zip  : 88888              # Enter your zip/postal code
Creating initial config file.
Change your preferences in '/home/YOU/.config/autolj.cfg'.
Sample crontab configuration is in '/home/YOU/.config/autolj.crontab'.

If you want to run the script from cron automatically each month, you can do this:


$ cp /home/YOU/.config/autolj.crontab mycrontab
$ crontab -l >>mycrontab
$ crontab <mycrontab
$ rm mycrontab

When you first run the script, use the --init command-line option to initialize the configuration file for the script. It will prompt for the email and zip/postal code associated with your Linux Journal subscription.

It saves that information in a file named ~/.config/autolj.cfg (if you saved the script with a different name, the base name of the config file will match the name that you saved the script under).

You can edit the configuration file with any text editor that you have on hand, or you can rerun the script with the --init option to re-create the config file (any existing changes that you've made will be lost).

The config file is a bash script that is sourced by the autolj script, so maintain valid bash syntax in the file. The config file contains a few other options that you may also want to change (the default value for each is shown):

You may have noticed that the save_dir, save_file and notify_msg variables are in single quotes (meaning that the variables they reference won't get evaluated when the config file is sourced by the script). Rather, the script evaluates them when it needs them. When the strings are eval'd, the following variables will be set:

By evaluating the strings when needed, you can customize where things are downloaded and how they are named.

Here are a few examples of what you can do:


# Download all types:
doctypes="epub mobi pdf"

# Organize downloads by document type:
#   $HOME/linuxjournal/epub   - epubs go here
#   $HOME/linuxjournal/mobi   - mobis go here
#   $HOME/linuxjournal/pdf    - pdfs go here
save_dir='$HOME/linuxjournal/${doc}'

# Organize downloads by month-year:
#   $HOME/linuxjournal/1-2018   - January
#   $HOME/linuxjournal/10-2018  - October
save_dir='$HOME/linuxjournal/${month}-${year}'

# Organize downloads by year-month (make sure month is 2 digits):
#   $HOME/linuxjournal/2018-01  - January
#   $HOME/linuxjournal/2018-10  - October
save_dir='$HOME/linuxjournal/${year}-$(printf %02d ${month})'

# Use the month name in the downloaded file:
#   Linux-Journal-January-2018.pdf
#   Linux-Journal-October-2018.pdf
save_file='Linux-Journal-$(date +%B ${month}/1)-$year.${doc}'

# Change the notification message.
notify_msg='The new LJ is here! The new LJ is here! 
 ↪${month}-${year}-${doc}.'

# Disable notifications.
do_notify=0

If you run the script from cron and your system can deliver email to an account that you monitor, you'll get a notification when the script manages to download any new issue files.

If you have the program notify-send installed on your system, the script also will "attempt" to send a notification to your desktop when it downloads any files (notifications being the pop-ups that appear at the bottom right of your screen).

I use the word "attempt", because if you're running the script from cron, notify-send may not work. If you want to disable the use of notify-send, set do_notify to zero in the config file.

If you don't keep your system running all the time, you also can set up the script to auto-run whenever you log in.

A few more notes before we wrap it up:

Notification Image

Figure 1. Notification Image

And that's it! Download Linux Journal now and automate your life a little bit.

Send email to ljauto@linuxjournal.com to report bugs or if you need help with the script.

—Mitch Frazier

LJ Archive