Scripting a Simple Download Scheduler

7
8943

Logging out

After downloading the necessary files, the next job is to log out. So we are on our way to write the logout.sh script. The steps to log out are similar to logging in. We will create a file called dir_out to store the keystrokes we need in order to log out.

As with logging in, the procedure to log out may vary with ISPs and connection-plans. For instance, in my case, I need to re-submit my user name and password in order to log out. My ISP doesn’t have an independent logout page. So when I open my browser with the URL of my ISP, even when I am online, I’ll have to enter the user credentials to access the logout page. However, for others, this might not be the case. If your ISP’s servers can auto-detect the connection status and pull up the logout page instead, when you invoke the browser with the ISP’s URL it’s easy to create dir_out, as you only need to run the following:

lynx -cmd_log=dir_out <URL >

…and keep hitting the Tab key till you reach the ‘logout’ link; finally, press Enter to log out.

Those in a similar situation can run the same command as above, resubmit a login ID after filling the text fields, and submit the logout after highlighting the logout link by moving over preceding links in the page. Now quit from the browser and provide the confirmation. Our dir_out file has now been created.

Again, it is possible that the logout isn’t successful at the first attempt. So let’s bring in the magic of the while loop again and our final logout.sh script should look like what follows:

#logout.sh
#!bin/bash
value=1
while [ $value -ne 0 ]
do
    lynx -cmd_script=dir_out <URL of ISP>
    value=$?
done

Shutting down the system

After essential downloads and a successful logout, it would be wise to shutdown the system—we should save electricity, seriously. Here, we can make use of the halt command. Note that you can’t be careless while you invoke halt. It will initiate a forced shutdown and all your unsaved data will be lost. Also, it can only be executed by the root user. Save the command in a separate file called shutdown.sh with the following data:

#shutdown.sh
#!bin/bash
halt

That’s it; all the essential script files are now ready. It’s time to put these in a schedule.

7 COMMENTS

  1. Remember how i am strugle to download something using 'aget'. But got a problem the the pages required to be authenticated first. Thank for the tips on using lynx

  2. Hey ,
    Awesome article, Really helps us folks using adlkerala which requires user authentication.
    So finally I don't have to stay up late night to make sure my downloads happen :P

    Thanks

  3. It's very useful to learn about linux.I really surprised about the article “Linux in Rocket Science”.
    It will be a really a good one to know about Linux.

LEAVE A REPLY

Please enter your comment!
Please enter your name here