Archive

Archive for May, 2011

Turning on/off display via Linux command line

May 30, 2011 1 comment

Found the commands at http://systembash.com/content/how-to-turn-off-your-monitor-via-command-line-in-ubuntu/:

To turn off monitor:
xset dpms force off
To turn on, simply press a key, or move mouse/mousepad.

Categories: linux, Tip

Change Centos ssh shell color

May 29, 2011 4 comments

When trying to ssh to Cento servers (Versions 5.X, haven’t tried other versions yet), the default directory color blue doesn’t work well with terminals such as Mac OSX Terminal using dark-background and Windows ssh client Putty. I haven’t found a way to change the directory color for a specific user but one to change for ALL users including root. So if you have root access and cannot stand for the hard-to-read color combinations, do the following

1) Edit /etc/DIR_COLORS as root
2) Locate line
DIR 01;34 # directory
and change it into
DIR 01;33 # directory

3) Save the file
4) Do the same steps for file /etc/DIR_COLORS.xterm
5) New logins can now see the new directory color

What step 2) does basically is changing the directory color from blue into yellow (it actually looks golden on black background). Step 1-3 take care of Mac OSX Terminal using Homebrew scheme, step 4 is needed if there are putty users.

EDIT [ 06/07/2011 ]:
Just found the answer to changing dir colors for a specific user here:
http://linuxtoolkit.blogspot.com/2009/06/painting-ls-on-bash.html

Categories: Bash, ssh, Tip

Requirements for a successful password-less ssh setup

May 27, 2011 Leave a comment

OK this password-less ssh issue has bothered me for quite a long time and I am officially making the requirements a post so I (and hopefully you) can benefit from it.

The list is quite simple:
1) chmod go-w ~/
2) chmod 700 ~/.ssh
3) chmod 600 ~/.ssh/authorized_keys

for ssh version 2 you might need to add “2” to the end of authorized_keys, that is, step 3) would become
chmod 600 ~/.ssh/authorized_keys2

Item 1) is easy to overlook, what the command does is to remove write permission for group (g) and others (o) from the home directory.

A good place to trouble-shoot the key-based login problem is /var/log/secure, if you see something like the following

Authentication refused: bad ownership or modes for directory /path/to/the/user_ssh_folder

You know you need to check and fix the ownership of directories/file mentioned in the list.

Categories: ssh, Tip

Beautify codes with a simple vim trick

May 20, 2011 Leave a comment

For codes that are not properly indented, use the followings to correct them with vim:

1) select the parts that are not correctly indented, you can
    a) select codes line-by-line by pressing v, then the up or down arrow key
    b) select a whole block of codes by entering viB
    c) select the whole document by entering ggvG

2) Now press the equal sign = and smile

Categories: Tip, vim

Diff text file remotely with local file

May 16, 2011 Leave a comment

Found a pretty neat solution at http://www.genlinux.org/2009/04/remote-diff-in-linux.html for comparing remote and local files. For example, if I want to compare the file

remote_ip:~/myscript.sh with the local version, I no longer have to copy the remote file to a temporary location and do a local diff, instead, with the solution provided in the link above, I can simply do


ssh user@remote_ip 'cat ~/myscript.sh' | diff - path/to/local/myscript.sh
Categories: Bash, linux, Tip

How to swith back to classic menu in Ubuntu 11.04

May 13, 2011 1 comment

Ubuntu is trying too hard to be like Mac – with Unity as the default system menu in version 11.04. I for one doesn’t like the change at all, especially I mainly use Ubuntu on my 10″ Acer netbook. The way how Unity works makes it very hard to keep track of windows/applications that are opened, applications that don’t come with a high-resolution icons looks very ugly on the dock.

Fortunately it’s not that complicated to switch back to the “classic” Unbutu menu (which I can say the best menu in the history of Ubuntu), here are the steps with screenshots:

1) Click on the Ubuntu icon on the top left corner, type “login screen” and click on the “Login Screen” application

2) You will see the following

3) Click unlock, enter password and the window should become the following, choose “Ubuntu Classic” from the dropdown menu, click Close

4) Log out current session and log back in and the classic menu should be back

Categories: Tip, ubuntu, Uncategorized

Using mysql transaction

May 10, 2011 2 comments

There are times when mysql tables need to be truncated (or certain rows need to be removed) before new records are inserted, transaction statement should be used to ensure data integrity.

Example:



// blah blah establish mysql connection

mysql_query('START TRANSACTION');
$res1=mysql_query('TRUNCATE TABLE tbl_test');

// insert new rows into tbl_test, if all went well
$res2=true;   // or false if something goes wrong

If ( $res1 && $res2 ) {
    mysql_query('COMMIT');
} else {
    mysql_query('ROLLBACK');
}

// blah blah close connection

Note: transaction feature is only available when InnoDB engine is used.

Categories: mysql, Programming Tags: , ,