Tuesday, October 30, 2007

Check your hard-drive's remaining life

Its always a horrible scenario when your hard-drive crashes - and adds more ghosts to it when you have important data into it.

It would always be nice to have some tool that can be used to find out the approximate life period remaining of your hard-drive. Well in newer SATA hard-drives they are using a Load/Unload mechanism for separating the disk and head. (detail explaination: http://www.linux-hero.com/rant/explanation-ubuntu-hard-drive-wear-and-tear).

In linux machines you can install 'smartmontools' to find out some interesting information about your hard-drive. This tool uses S.M.A.R.T (Self-Monitoring, Analysis and Reporting Technology) technology available in new hard-drives. This gives a specific count of Load/Unload done on your hard-disk. Normal hard-disk has 600,000 of Load/Unload cycles. Following is the method to find out the remaining life time of your hard-disk.

If you are a ubunbtu user like me simply give the following command:

sudo apt-get install smartmontools


It will install 'smartmontools' to your system. After than give the following command

sudo smartctl -d ata -a /dev/sda | grep '193'


It will show output something like this:

193 Load_Cycle_Count        0x0012   097   097   000    Old_age   Always       -       30385


Here in the last the number is 30,385 which is load/unload cycle count of my hard-drive. Well my drive is only 1.5 months old and it has already used 30,385 cycles.

Tuesday, July 31, 2007

Magic Audio & Video tricks using SSH and X

Think of this: Your friend is working on your Linux desktop machine, and you are working on another Linux machine either at home or office. Your friend is editing some files and BOOM - speakers start making horrifying sounds, some horror video starts playing as full-screen mode... And if you have access to your home's electricity connection from that computer then your friend is going to have the worst experience with ghost!!!

I will let you think of more horrifying tricks later on after you know how to setup environment like this. All you need is SSH daemon running on destination machine and access to that machine using internet. Of course you must have access to user account that has all the permissions to running X server, a root access will grow two horns on your head !!!

If you are new to SSH, you should see this tutorial on SSH.
Setting up the SSH daemon in server machine is simple, install 'sshd' package and as root give following command:
root@servername# sshd

It will start a ssh daemon and you are all set to login from remote machine.

Login using SSH with -Y option:
user@localname$ ssh -Y username@servername

Using -Y you can securely forward all X11 connections to your local machine. So now fire-up your loved MP3 music player (i prefer amarok, great player with great interface) and your familiar window will greet you. So when you start playing music, it will use server machine's speakers, not local machine's !!! You can download some horrifying sounds and set up a script to play them one by one to be prepared for horror attack...

Now as you can see that we can open almost any GUI window in local machine, lets start playing some video using vlc or mplayer. But whats this, the video is played in local machine... Well to play the video in server's monitor screen, which is screen no 0 (or in pure X term display :0.0 ). To make sure that your video plays on server's monitor not in local, change your DISPLAY environment variable from localhost:10.0 (somthing like that) to :0.0 .

Check your DISPLAY variable value in your ssh session:
user@servername$ echo $DISPLAY
If its not set to :0 simply change it using following commands:
user@servername$ export $DISPLAY=:0.0
or if you are using 'csh':
user@servername$ setenv $DISPLAY :0

To make sure that the X display number is :0.0 , give the following command in your ssh session:
user@servername$ ps -ax | grep 'X'
It will show something like this:
user@servername$ 3744 tty7 Ss+ 2:01 /usr/bin/X :0 -audit 0 -br -auth /var/lib/gdm/:0.Xauth vt7

Here, the value after '/usr/bin/X' is ':0' so your display number is 0. If there are more than one display running than you may have to do trial and error to find the display number.

Now you are set to play videos in server machine's monitor. Use vlc with following options:
user@servername$ vlc -f videoname.avi
or if you like mplayer:
user@servername$ mplayer -fs videoname.avi

Now you have learn the dark side tricks of SSH go and practice it to be master of it. And when you successfully execute this mission don't forget to tell me your friend's reaction!!!

NOTE: If you try to use firefox over SSH, when we give normal 'firefox' command it runs locally not remotely, so music will be played in local machine. To fix this problem start the firefox with following options:
user@servername$ firefox -no-remote

This will start the firefox in remote machine so any music played in it will play in remote machine's speakers.... enjoy.

- Avadh Patel