Wake up your PC and download stuff in an early morning (revisit)

There was an old post about this topic. It talked about how to wake up your pc in the early morning, then downloading stuff, eventually shuting down by itself. But it only focused on Kubuntu and its applications, the method may not work on other favours of Linux distributions. In this occasion, I talk about how to wake up your pc in general Linux environment.


Again, I need to remind you why I need to wake up my pc in the early morning (e.g. 3am) to download stuff. There is no download limitation in America and parts of Asia. In Australia, download is capped once it reaches its limitation. That means the internet connection becomes slow and the speed is only 56k/s or below. Some ISPs are offering peak-usage (9am – 3am next morning) & off-peak-usage (3am – 9am) in a single package. That means even my peak-usage runs out, I am able to download podcasts or movies at full speed between 3am – 9am. There is a problem though. It is very difficult to wake up myself in 3am to download stuff. But a little twist to my BIOS and Linux box will do the job very well, here is how:

Step 1: Set the alarm in BIOS
* Start your computer by pressing Del in the number pad, so your pc enters the BIOS.
* Select power management (or something similar)
* Enable the alarm & set the alarm time
* Save and exit BIOS

After this step, your pc will wake up at a specific time and boot into your 1st choice operating system. In my case, it will wake up at 3am each day and boot into Linux.

Step 2: Use cron to schedule the download
* Open your terminal
* Run sudo crontab -e. This will open cron, but in power user mode. The reason to use power user mode is I am able to issue the command /sbin/shutdown to shut down my pc. I haven’t find a way to do so without being a power user. (If you know how, you can tell me via comments)
* Put this line 06 03 * * * /home/kenpeter/utils/shell/wget/wget.sh into your cron. I will get into the wget.sh shell script later. This line tells my Linux to run wget.sh at 3:06 am (The pc wakes up at 3am each day). You need to modify the time, which is suitable to your schedule.
* 00 05 * * * /sbin/shutdown -h now. This line will shut down my pc at 5am. That means I gave my pc about 2 hours to download stuff. Again, modify it to meet your needs.

Step 3: Create the wget.sh script
I create wget.sh in /home/kenpeter/utils/shell/wget/wget.sh. The source is included below. /home/kenpeter/utils/shell/wget/downloads.txt contains the files, which I want to download line by line. The script reads each line in downloads.txt and download it to /home/kenpeter/. After a file is downloaded completely, the script will remove the entry in downloads.txt. You may notice that I specify several full paths in the shell script. That is because when cron executes this script, it doesn’t know where to find downloads.txt, for example. Also, I use wget -c to download a file here. If the download stops in half way, wget will pick up the last portion it downloads and resumes it.



while read LINE
        FILENAME=`/usr/bin/basename "$LINE"`
        wget -c "$LINE" -O /home/kenpeter/"$FILENAME"
        echo "$LINE" > "$TMP"
        NEWLINE=`sed 's$\/$\\\/$g' $TMP`
        sed -i "s%$NEWLINE%%g" "$DL"
        echo "Finish \"$FILENAME\"" >> /home/kenpeter/my_wget.log
done < "$DL"

rm -f $TMP
rm -f sed*

Step 4: specify what files you want to download
In my case, I specify what files I want to download line by line in /home/kenpeter/utils/shell/wget/downloads.txt. An example file will be:

What I have done here:
* Specify the files I want to download in downloads.txt
* Wake up my pc at 3:00 am
* Download stuff at 3:06 am (If it cannot finish, do it next day)
* Shut down at 5:00 am

It works very well for me and it was an interesting learning experience. I encourage you to try it yourself. One last thing, please remember to turn off your BIOS alarm, once you had finished your downloads, otherwise it becomes annoying.

A simple booking system (version 1.0) in ruby on rails

Firstly, you may wonder why I created this simple booking system. It was an interview question and required me to build it in 40 minutes. In fact, it took me much longer time to create this simple booking system, as it provides much “better” functionalities and user interface. 🙂

This simple booking system (version 1.0) allows users (i.e. patients) to create a profile and book/cancel an appointment with a surgeon. On the other hand, the surgeon can also create a profile and view/cancel whom makes an appointment with her/him. The surgeon can book/cancel an appointment with himself/herself. This may sound strange, but the idea is to allow the surgeon to have some flexibility.

You can download the source code and the SQL file below. What you need to do is to extract the booking system (in .tgz format) into your localhost or server, then import the SQL file into MYSQL database. You may wonder doesn’t rails supports migration and running rake db:migrate should insert the data structure and data automatically. That is because something were missing or broken during the entire migration process, during my development. Well, it is my bad!

There are lots of places can be improved. For example, an administration back end needs to be built, so surgeons and users can be managed easily.

You can download it and do whatever you want. Suggestions are always welcome!