Dec 28, 2008

gegls in Ubuntu

Got to know about this easter-egg-thing in ubuntu.
A virtual Easter egg is an intentional hidden message or feature in an object such as a movie, book, CD, DVD, computer program, web page or video game.

This is just a funny hidden game.
Open the Run application Dialog using ALT + F2 and then type "gegls from outer space" without the quotes and then just hit Enter.

The game pops up.
Screenshot:


Enjoy the game!

Got it from ester egg archive.

Dec 17, 2008

Schedule a job in cron

For the task that you have to run regularly in some period, scheduling it in the cron is the one and only way for it.
For this run this in terminal:
crontab -e

This will start the vi editor and load the current cron table file for this user, or a blank file if none exists. In a new line type the following

A B C D E < path to the script > [Arguments if any]


Where:

  • A = minute of the hour

  • B = hour of the day

  • C = day of the month

  • D = month of the year

  • E = day of the week



Example:
To schedule a Task daily at 9 in the moring that lies in /home/sata/script. I use the following.
0 9 * * * /home/sata/script

Nov 15, 2008

solve "Communications link failure" in matlab

Recently while i was working on my project in matlab. I got the following error.
Connection failed: Communications link failure

Last packet sent to the server was 0 ms ago.
??? No constructor 'com.mathworks.toolbox.database.closeTheDatabaseConnection' with matching
signature found.


After I lost 2 hrs of my time, I remembered I had gone through the same error in Hibernate/mysql.

The solution is so simple:
Just comment out the following line in my.cnf(the mysql configuration file). :)
skip-networking

so that it looks like this:
#skip-networking


Finally restart the service mysql.

To know why see my earlier post:http://howtoxyz.blogspot.com/2008/09/solve-commysqljdbccommunicationsexcepti.html

Nov 11, 2008

Run GUI application as another user.

I knew that if there is some flaw in irc-client it will leave a security loop in the system. And the attacker get the privilege of the user running the irc-client. And you know what it will lead to.
So specially to run the X-chat (a irc client), I created another user irc with very less privilege.

Then I tried running the xchat as follows:
suraj $ su irc
Password:
irc$ xchat
No protocol specified

(xchat:6966): Gtk-WARNING **: cannot open display: :0.0


Hum.. There occured a problem. The app couldn't get handle to the grapics display.

So here is the solution:
$ sudo apt-get install sux

and run
$ sux irc xchat
Password:


Provide the password of the user irc and see the application launching.

Oct 30, 2008

Disable root ssh login

Disabling ssh is one of the major security enhancement. It is just a simple task. What you need to do is edit a file ("removing a #") and restart the service. Here it goes,
First you need to find the following line and remove the comment from the file "/etc/ssh/sshd_config".
#PermitRootLogin no

ie. Just remove the preceding "#"

You can edit it in your favorite editor. But remember you need to be have root access to edit it.

Or simply you can run the following command from terminal
sudo sed -i "s/#PermitRootLogin/PermitRootLogin/g" /etc/ssh/sshd_config

Now, For this to take effect, you need to restart the service:
sudo /etc/init.d/sshd restart

Sep 29, 2008

reset mysql root password

Recently, one person left me in his system to solve one of his problem associated with webservice.
He left me and went somewhere and asked me to solve the problem before I left.

During this i requited the mysql root password, but he want there. So i googled to reset the mysql password. And here is what i did to reset the password.

$ sudo /etc/init.d/mysql stop

$ sudo mysqld_safe --skip-grant-tables --user=root

$ sudo mysql -u root


Run this query in mysql prompt:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;


Finally kill this mysql process and restart it safely:

$ sudo /etc/init.d/mysql start


ref: http://www.linuxweblog.com/blogs/sandip/20060330/reset-mysql-root-password

Sep 28, 2008

solve "com.mysql.jdbc.CommunicationsException"

This is the error that I got when trying to connect to mysql (of lampp package, yes in linux) using Hibernate in java.

WARN 2008-09-28 13:55:17,116 org.hibernate.cfg.SettingsFactory -s Could not obtain connection metadata
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused

STACKTRACE:

java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.(Socket.java:366)
at java.net.Socket.(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:271)


Basically, the problem here is because of jdbc connector, which was unable to connect to the database. There are two ways of communication with mysql in linux.
  1. Don't listen on a TCP/IP port at all, if all processes that need to connect to mysqld run on the same host. There interaction with mysqld are made via Unix sockets or named pipes which is .sock file.

  2. B. Simply listen on a TCP/IP port. This allows remote communication to the database too.


Lampp initial configuration sets the first method of communication. And the sock file is created in < lampp root dir >/var/mysql/mysql.sock . But by default the jdbc search it in "/var/run/mysql/mysql.sock" (somewhere like this). Due to this problem, jdbc wont be able to connect to the database.

There are many ways to solve this:
The simple one is to switch to second type of communication method.
find the following line in <lampp root dir >/etc/my.cnf
skip-networking

and comment it.
# skip-networking


Hope this helps you out.

Aug 8, 2008

Change your terminal prompt (bash)

I always get messed up with the output and the prompt. I wanted to so sth that would make the prompt distinguishable. I also hate the (increasing) length of prompt ie showing the full current path.

Ok here's what and how I did. It easy and a bit tricky.

You must have known that while starting a (bash) terminal, the terminal itself runs the script in the "~/.bashrc" file. If you didnt know, know it now.

Ok. Its straight forward, what we do now is add few lines to the end of the file. So open the file in any editer you like and add the following line at the end of the file

BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
PS1="\[$BLUE\][\u@\h]\[$RESET\] "


Here the env variable PS1 is the normal terminal prompt. FYI PS2 contains the continuation prompt in bash.
So what this says is "DISPLAY A PROMPT IN BLUE COLOR SHOWING [USERNAME@HOSTNAME] AS PROMPT".

Here is the screenshot of my (gnome-)terminal:
gnome-terminal

Zoomed
Zoomed gnome-termial

EDIT:
Here is a list of Escape Sequence that yuu can use:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html

Jul 29, 2008

Applications menu not working in Ubuntu

This was the problem faced by Sanaklp, one of my friend. He was trying to install some apps via apt-get. during the installation he was warned about for no space in root partition. Somehow the system was working fine even after all this. But once he rebooted his system, he couldnt see any sub-menu under "Applications" menu. At the moment i reached there and he asked me to resolve the problem.

I thought that some configuration associated with the menu must be wrong and I was right. I just deleted the config file at /home//.config/menus/applications.menu.

$ rm /home/<username>/.config/menus/applications.menu

What happens after you delete this file is the system assumes your menu to be same as the default. Whenever you change the menu (Right click and "Edit Menus"), the system will again generate the file which you deleted earlier.

Relogin and your system must be fine now.

Jul 22, 2008

NETDEV WATCHDOG: eth0: transmit timed out

NETDEV WATCHDOG: eth0: transmit timed out
eth0: Transmit timeout, status 00000004 00000249

This was the error that i got in my kernel log message.

I was unable to use internet in my laptop "MS 1006". I tried setting up the network in either way (dhcp and static) but non of these solved the problem. I got terribly wired, as i could see no other message beside "destination host unreachable" and waiting for never offering, DHCP.

I even wasted 2 days and even googled for many keywords. But i couldnt get the solution. But finally the end of the second day was fruitful. I solved it.

This was due to the interrupt conflict that occured between the acpi and network modules.
I turned off acpi while booting by adding following words at the end of the boot option.

Before:

title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,1)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=e89b77d0-3183-4036-b508-15d9a23dc86c ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet


After:

title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,1)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=e89b77d0-3183-4036-b508-15d9a23dc86c acpi=off ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet


Enjoy the net.

ref:

  1. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/183588

  2. http://bugzilla.kernel.org/show_bug.cgi?id=7595

Jul 17, 2008

Solve [mount_point cannot contain the following characters: newline, G_DIR_SEPARATOR (usually /)]

I recently suffered from this problem. I googled it and finally solved it.
This is a bug filed here.

I specified the mount point like "sata/160GB", expecting it to mount the device in "/media/sata/160GB". But the problem started here. The system expects only a word here with no slashes(/) in it. While mounting it just creates a folder which you provided, in /media and mounts the volume there.

And this is what I did:

Open gconf-editor in terminal:
$ gconf-editor
In the left panel:
Goto:
System -> Storage -> volumes

Here you will see the mount point you specified for the device.
Change it to just a single word (OR just remove it :) )
Thats it. Replug your device.

Enjoy!!!

EDIT:
1. Do not use sudo for this purpose.
See this comment by Anonym... (Thanx to Anonym) for detail.

2. Sometimes instead of System -> Storage -> volumes you may also get System -> Storage -> drives , depending upon what you messed up. The rest process is same.

Jul 13, 2008

writing-udev-rules, the other way

Here's my earlier post on about writing the udev rules:
writing-udev-rules, the easier way
This will give you a bit of understanding about what a udev-rule is and how can you write a udev rule on the basis of vender-id and product-id.

Here is the other way (Its easier but a bit time consuming):
So here you go..
Insert your usb-device, and watch the log:
# tail -f /var/log/messages
Jul 13 16:47:20 workbench kernel: [ 5418.740803] sd 7:0:0:0: [sdb] 312581808 512-byte hardware sectors (160042 MB)
Jul 13 16:47:20 workbench kernel: [ 5418.743055] sd 7:0:0:0: [sdb] Write Protect is off
Jul 13 16:47:21 workbench kernel: [ 5418.743072] sdb: sdb1
Jul 13 16:47:21 workbench kernel: [ 5419.323103] sd 7:0:0:0: [sdb] Attached SCSI disk
Jul 13 16:47:21 workbench kernel: [ 5419.323163] sd 7:0:0:0: Attached scsi generic sg2 type 0

Notice the third-last line. It shows that the device is mounted as sdb1.
Now lets dig into it.
# udevinfo -q path -n /dev/sdb1
/block/sdb/sdb1


This shows the devpath of the device.
From this devpath you can see a lot of information.

# udevinfo -a -p /block/sdb/sdb1

At the very first line of the output you will see:


"Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device."

This pretty much explains itself.

And the (trimmed-)output is:

looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"

looking at parent device '/block/sdb':
KERNELS=="sdb"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{dev}=="8:16"
ATTRS{range}=="16"
ATTRS{removable}=="0"
ATTRS{size}=="312581808"
ATTRS{stat}==" 206 10881 12228 1688 0 0 0 0 0 1272 1688"
ATTRS{capability}=="12"

...

looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x24dd"
ATTRS{subsystem_vendor}=="0x8086"
ATTRS{subsystem_device}=="0x4246"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="19"
ATTRS{local_cpus}=="ff"
ATTRS{modalias}=="pci:v00008086d000024DDsv00008086sd00004246bc0Csc03i20"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""

looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""



So you can choose any block and write the rule for that.
Let me zoom into a block

looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"

So here's the rule for this :
KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{dev}=="8:17", ATTR{start}=="63", ATTR{size}=="312576642", SYMLINK+="myDisk"

Now, this is also not the only rule. Go on! Generate your own rule. Mind with the spaces like in case of ATTR{stat}==" 11011 11620 0 0".

Finally place the rule in /etc/udev/rules.d/60-persistent-storage.rules. Then Plug out the device and again plug-in to see the change.


# ls /dev/ | grep my
myDisk


That's it.
If you want to learn more about it:
http://reactivated.net/writing_udev_rules.html
http://ubuntuforums.org/showthread.php?t=168221

Writing udev-rules, the easier way

What is udev-rules?
udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.

Okay, here i will show you howto write udev-rule for a USB hardisk.


# lsusb

Bus 005 Device 003: ID 04fc:0c25 Sunplus Technology Co., Ltd
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 004: ID 062a:0000 Creative Labs Optical Mouse
Bus 001 Device 001: ID 0000:0000


This gives us two information, one of them is what we want.
Very first line shows that I have a Device with vernder id: 04fc and product id:0c25 named "Sunplus Technology Co., Ltd "

The second-last line points my USB-mouse, which is not of much interest now.

Now move to the /etc/udev/rules.d directory

# cd /etc/udev/rules.d


As the device is a storage device we will be writing the rule in "60-persistent-storage.rules"
So open this file with your prefered editor (I recommend scite in gui and vim in console) and add the following line:
KERNEL=="sd*[0-9]",SYSFS{idVendor}=="04fc",SYSFS{idProduct}=="0c25", SYMLINK+="sata"

This informs udev-manager, that if any storage device with vendour-id, 04fc and product-id 0c25 is plugged into the system add a symlink in /dev with name, sata.

Note: This rule is specific to the device only. And also this is not the only rule that you can write.

This is the easiest way. And there is another way round to work on this: >Here<

Jul 11, 2008

Generate your gpg-key


GNU Privacy Guard (GnuPG or GPG) is a replacement for the PGP suite of cryptographic software. It is freely available and is a part of Free Software Foundation's GNU software project.

Generating your gpg-key in linux
Terminal,:) the following:

~$ gpg --gen-key

You will be asked with the following options:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)

*nux-platform developers are crazy... there is no any reason for sth like this 1, 2 and then suddenly 5 ;)

Choose the option according to your choice if you dont know what DSA and RSA are. Just gooooogle them. I recommend choosing (2) as it gives better security. Remember it's just for signing purpose.

DSA keypair will have 1024 bits.
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years

Choose 0 if you dont want it to expire.
Provide your Real name ( at least 5 chars ), Email address and Comment.

Conform (enter alpha-O) it and wait few secs and your key is ready.

Ps: You may be asked to move your mouse or do any thing on your desktop to refill the pool of random numbers.

Jun 18, 2008

I helped mozilla to make record.

I helped mozilla to make the record of more than 8M (and counting) download in a day.
Here's my certificate.



where is yours?

Jun 5, 2008

Removing the login message.

I dont know about you, but i dont like the message like "... you have new message ...." that is shown after logging in.
If you are like me and want to remove the message. Follow the following procedure. Its pretty simple:

Just create a file named ".hushlogin" in the home directory of the current user.
$ touch .hushlogin

If you want to hide this message for each new user that is created you can create the file named ".hushlogin" in /etc/skel directory.

# touch /etc/skel/.hushlogin

Remember you need root access in the second case.

Apr 16, 2008

UserAgent switcher in Mozilla

Here's a user-agent switcher for mozilla:

http://chrispederick.com/work/user-agent-switcher/

I hope it will be of great use.

Happy Hacking!

EDIT:
I got a video tutorial for it too. Find it here.

Mar 18, 2008

Change ssh Welcome Banner

/etc/motd

Everything you write in this file is shown as welcome banner when someone enters your into your box via ssh.

So sudo gedit /etc/motd :) enjoy!!!

Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

Here's the quick and easy way to re-enable Grub.

1) Boot off the LiveCD

2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub "prompt", and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.

$ sudo grub
> find /boot/grub/stage1
> root <the output of above command>
> setup (hd0)
> quit


Reboot (removing the livecd), and your boot menu should be back.