Sing me a lullaby lappy!

It is often the case you want to listen to some music before you drift away into deep slumber. Well, in order to do that, if you’re using your lap or phone, you’ll have to manually stop the music after a while. And that will be either at the time a nice sleep is at its verge or waking up in the middle of your sleep. But that’s not how a lullaby works, is it? Nope. A lullaby gets us to sleep, continues a little while after we are asleep and then stops. We are going to see how we’re going to do that with our computer.

Its really simple. As usual, I’m on my Ubuntu 10.04 while doing this and I’m assuming we are using totem movie player in the rest of this post.

We have already started the movie player and it is playing a list of our favourite musics. You have given the ‘repeat’ option and you’re ready for bed.

Since everything running on your computer is a process, totem too is a process and it will have its own unique process id. We need to get that first. We use the ps command for that which gives a ‘snapshot of the current processes’. We give an option -e to it in order to select and display all the processes and from that list, we grab (grep) totem by the collar. So this is how it will look:

haris@asylum:~$ ps -e | grep totem
 7315 ?        00:00:30 totem
haris@asylum:~$

That number to the left is totem’s process id. Now let’s say you want your music to last for 45 minutes assuming you will sleep within half an hour or so.

Run date.

haris@asylum:~$ date
Sun Oct  2 06:43:21 IST 2011
haris@asylum:~$

It is 6:43 now. Let’s say I want the music played till 7:30 and then totem should stop. There is a cool command called at. Here is a demonstration:

haris@asylum:~$ at 0730
warning: commands will be executed using /bin/sh
at> kill 7315
at> <EOT>
job 8 at Sun Oct  2 07:30:00 2011
haris@asylum:~$

That’s it. Now I can lie down to sleep and at 7:30 sharp, totem will be killed. Note that <EOT> is not typed into the terminal. You must press ctrl-d for that.

This is most useful when you have a torrent running and you don’t want to have your laptop suspended or shutdown for the night.

Otherwise you can use the shutdown command itself to have your laptop shutdown or halted after a specified amount of time. Its the trick we use while giving my 3 year old niece food. We use the shutdown command to make the computer shutdown automatically after 20 or 30 minutes and when it does, we tell her, “Oh, its a power failure. We’ll watch cartoons tomorrow, okay?” and gets her away from the monitor.

The shutdown command is pretty simple. If you want your system to be shutdown in say, 30 minutes, you do:

haris@asylum:~$ sudo shutdown -P +30
[sudo] password for haris:

Broadcast message from haris@asylum
    (/dev/pts/2) at 6:55 …

The system is going down for power off in 30 minutes!

You can hit ctrl-c to quit the order. The -P option is to power off. There are several other options. Refer the man page of shutdown for them.

Check it out.

Advertisements

Hey! What do you think? Share your thoughts. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s