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.
The author is a third-year B. Tech computer science student from College of Engineering (CET), Trivandrum. He is an active member of fsug-tvm and also the FOSS group at his college. He loves shell- and python-scripting, and is an evergreen fan of KDE.