Thursday, December 15, 2011

One line Python Web server

if you have python installed, go to your terminal. Go to the directory you want to serve HTML files from, then type one of the following, depending on your python version:

Python 2.x:

python -m SimpleHTTPServer


Python 3.x:

python -m http.server 8000

Monday, December 12, 2011

Get Notifications from Your Scripts with notify-send

Notify-send is a great application for notifying you when an event has occurred. An event such as a script running to completion.

If notify-send is not installed on your machine already, install the package "libnotify1" (or possibly just "libnotify") from your repositories.

Once installed you can simply type the following, at the command line, to display a pop-up message near your system tray:

notify-send "hello"
By default the message will be displayed for 5 seconds. To change how long a message stays displayed use the "-t" switch. This will change, in milliseconds, how long the message is displayed. Enter "-t 0" to leave the message up until the user closes it.


notify-send "This message will be displayed for 3 seconds" -t 3000
notify-send "Click me to close me." -t 0


You can even add a title and an icon to the notification.

notify-send "This is the Title" \
"Check out the cool icon" \
-i /usr/share/pixmaps/gnome-terminal.png

When used in a script you could set it to notify you periodically by placing the command in a loop:

#!/bin/bash

while [ 1 ]; do
notify-send "Up Time" "`uptime`"
sleep 5m
done

Disabling Bash History Temporary

Say that you’ve got to pass some password as command line argument to something. It would probably be a bad idea to store it in your ~/.bash_history, but clearing the file isn't desired either. So you need to temporary disable the command history for the current session. You can do it by unsetting the HISTFILE environment variable.

unset HISTFILE


The result is that while the session is active you can access the history as usual, but it won't be saved to the disk. History for other sessions, will behave as usual.

Thursday, August 25, 2011

Wednesday, February 3, 2010

how to ssh without password

Let say you want to access to a machine with IP 192.168.1.10, and make sure you have
command ssh, ssh-keygen, ssh-copy-id.
First, generate the ‘key’, the key will be used to open the remote machine’s door.
ssh-keygen

You will see something like that
Enter file in which to save the key (/home/myname/.ssh/id_rsa):

Whatever it appears just press enter until it ends, press enter for passphase as well.
Okay, the ‘key’ will be generated, something looks like ~/.ssh/id_rsa.pub
Copy over the ‘key’ to remote machine, and enter your password
ssh-copy-id -i ~/.ssh/id_rsa.pub macspc@192.168.1.10

Done. Now you can ssh 192.168.1.10 with username macspc without password.
ssh macspc@192.168.1.10

What I Did

~? ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/brijith/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/brijith/.ssh/id_rsa.
Your public key has been saved in /home/brijith/.ssh/id_rsa.pub.
The key fingerprint is:
4b:71:39:69:36:13:0a:69:65:21:de:5f:24:b4:1c:b6 brijith@Newmegadisk
~? ssh-copy-id -i ~/.ssh/id_rsa.pub macpc@192.168.1.10
29
Password:
Now try logging into the machine, with "ssh 'macspc@192.168.1.10'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.


Now you can login through ssh with out a password

ssh macspc@192.168.1.10


It wont ask password any more.

If you want to launch application of the remote system in your PC using ssh use -X option of it

eg:

ssh -X macspc@192.168.1.10

and then give the application name you want to launch in resulting terminal
eg:
gedit&

This will launch gedit of remote system in your system

gedit

Password Less Dump in MYSQL

MySQL is perhaps one of the most popular database systems currently available. It has a lot of great features, it's open source, and a lot of Web-based applications use it for their back-end storage.
One important part of running a database is maintenance, and that includes backups. However, due to the fact that the database is password-protected, one can't automatically back up the database without interactively supplying the password. And, depending on what you need to back up, you may even have to use the MySQL "root" user to do a full backup.
You can avoid those hassles by creating a configuration file for the user to do the backups (i.e., /root/.my.cnf). This user does not need to be the system root user; it can be any normal system user who has access to the database as the database's root user. The ~/.my.cnf file would look like:
[mysqldump]
user = root
password = secret

With this, you can automate a dump of the database via a cronjob, without being asked for a password. You will still need to supply a password using the mysqladmin or mysql tools, but not with mysqldump. Now, to automate the backup, run the following script out of cron:

#!/bin/sh
mysqldump -u root --all-databases >/var/lib/sqldump/mysql.dump


Some people may consider this horribly insecure, but it's no more insecure than doing it manually, especially if this is being done by the root (or even mysql) user. If the file is adequately protected (mode 0600), your database is just as safe. Remember that an attacker would have to obtain root privileges in order to read the file. If that attacker had root privileges, they could simply make a copy of your database, retrieve it, and open it on any MySQL installation at their home and be able to read the contents of your database at their leisure, without once requiring the database password.
Because there is just as much (or just as little, if you prefer) security in supplying the database root password in a configuration file, there is really no reason not to do it. The benefit is that providing password-less access can make things like automated database maintenance far easier.

Setting Up offline multiple language dictionary in Ubuntu

All of you might have see a Dictionary application Under Office Menu in every Ubuntu distro. By default it is configured to work with online dictionary server. So the people we have an Internet connection will miss this application. No,not really,It is possible to configure so that it can work well as if it is online. following are the steps

Start Up synaptic and find the following packages and mark for installation

dict
dictd


these are the server and client for a dictionary services

apart from the above if you continue searching in sequence (to the above mentioned packages) you will find a whole lot of dictionaries -the ones i have installed are
dict-bouvier
dict-devil
dict-elements
dict-foldoc
dict-freedict-eng-deu (english to german)
dict-freedict-eng-hin (english to hindi)
dict-freedict-hin-eng (hindi to english)
dict-gcide
dictionaries-common
dict-jargon
dict-moby-thesaurus
dict-vera



After installing this (and other dictionaries of your choice) there is a small tweak we need to do to make the dictionary work offline

Go to Applications --> Office--> Dictionary and run the programme Dictionary

In the Open Application go to Edit --> preferences
In Source select ADD and
in description add any name you want to use for your customized dictionary services (replace source with a identifiable name)
Let transport be as it is (Dictionary Server)
change Hostname to 127.0.01 (replace dict.org)
Port - Leave as it is. enter add then in the Select a Dictionary Source for looking up words Select the Dictionary source your just added
Enter Close
Type any word to test if the dictonary works (you can / should test with your internet off)
If you get a meaning or any output means its working. Congratulations.