The Complete Magazine on Open Source

Scripting a Simple Download Scheduler

5.28K 7

Logging out

After downloading the necessary files, the next job is to log out. So we are on our way to write the 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 script should look like what follows:
while [ $value -ne 0 ]
    lynx -cmd_script=dir_out <URL of ISP>

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 with the following data:

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

Pages : 1 2 3 4



Your email address will not be published.