Thursday, March 26, 2009

Mysql Password Reset

Edit my.cnf and add the line "skip-grant-tables" in "[mysqld] section and restart the mysql. You can login to mysql without password.

To change the password execute following command @ mysql prompt.

mysql> update mysql.user set Password=PASSWORD('<>') where user='root';

Vi Tricks

This time, I'll show you how to make a Web server running Apache and Linux survive heavy loads.

http://rudd-o.com/en/linux-and-free-software/tuning-an-apache-server-in-5-minutes

Tuning Primer

Tuning the performance of MySQL can be a really hard job to do.There are many thinks to consider and no two servers are identical so there is no universal solution. Tuning Primer is a script that will help you tune your mysql installation by providing very healthy recommendations based on past mysql records.

http://day32.com/MySQL/tuning-primer.sh

MySQLTuner

MySQLTuner is a script written in Perl that will assist you with your MySQL configuration and make recommendations for increased performance and stability. Within seconds, it will display statistics about your MySQL installation and the areas where it can be improved.

http://tools.assembla.com/svn/mysqltuner/

Tune Mysql

MySQL Performance site, published tips about tuning your MySQL server Performance.

From the article:
My favorite question during Interview for people to work as MySQL DBAs or be involved with MySQL Performance in some way is to ask them what should be tuned in MySQL Server straight after installation, assuming it was installed with default settings.

I'm surprised how many people fail to provide any reasonable answer to this question, and how many servers are where in wild which are running with default settings.


http://www.linuxweblog.com/tune-my.cnf

http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/

Optimizing the database regularly will also help you run the server fast! Put the following line in cron.

mysqlcheck -o --all-databases

Wednesday, March 4, 2009

AWK Magic

Suppose you have the two files with following content

ip.txt

bmdes001;172.16.33.100
bmdes002;172.16.33.101
bmdes003;172.16.33.102
bmdes004;172.16.33.103
bmdes005;172.16.33.104

dhcp.txt

00:1A:4D:A6:B5:4C;bmdes001;
00:1D:09:25:7C:B2;bmdes002;
00:1D:09:19:82:EF;bmdes003;
00:1D:09:26:45:46;bmdes004;
00:1D:09:19:62:79;bmdes005;

And you want to combine the two files where 1st column of ip.txt file matches with 2nd column of dhcp.txt then following is the command for you.

awk 'BEGIN{FS=";"}FILENAME ~ /ip.txt/{a[$1]=$2}FILENAME ~ /dhcp.txt/{print $1,$2,a[$2]}' ip.txt dhcp.txt

00:1A:4D:A6:B5:4C bmdes001 172.16.33.100
00:1D:09:25:7C:B2 bmdes002 172.16.33.101
00:1D:09:19:82:EF bmdes003 172.16.33.102
00:1D:09:26:45:46 bmdes004 172.16.33.103
00:1D:09:19:62:79 bmdes005 172.16.33.104

Tuesday, March 3, 2009

Find and Replace several files

If you need to change the same thing in hundreds of files then following script is for you. It will create the backup of every file with .bak extension.

perl -pi.bak -e 's/your-find-string/your-replace-string/g' filename

Example:
perl -pi.bak -e 's/abc/xyz/g' *.php 

This will replace abc with xyz in all the files in current directory which are with .php extension.

Basic Interview Questions

  1. How many arguments shell script can take
    Ans: execute "getconf ARG_MAX" the output will tell you how many argument shellscript can take.

  2. How do you capture variable in shell script
    Ans: Using $1,$2 etc.

  3. What is difference between tomcat and jboss
    Ans: Tomcat is a pure servlet engine, with no EJB. JBoss supports EJB and JMS related stuff. JBoss is a full J2EE application server.. it supports the bulk of the J2EE spec. It is more common to refer to J2EE as a more complete reference of what an application server can and should include, of which Tomcat only implements a part, while the complete download of JBoss (including Tomcat) conforms to the full J2EE specification, and hence is amore "complete" application server.

  4. What is difference between sh file-name and ./file-name
    Ans: ./ can be executed only if the file has execute permission

  5. What is the command to check the free ports
    Ans: use “nmap”

  6. How do you reset password in mysql
    Ans: Start mysql with “mysql-safe –skip-grant-tables”

  7. What is the Default flag for "Kill"
    Ans: Default flag for kill is "TERM/-15" 

  8. I create a user, the user logs in but can't create files in his dir. Why? The dir permissions are ok.
    Ans: check quota, check if disk is full

  9. df and du show different values, why ?
    Ans: http://sysunconfig.net/aixtips/df_du_diff_out.txt

  10. How to implement round-robin load-balancing in bind (dns) ?
    Ans: Add two A records for the same hosts with different IP and set TTL as zero for them.

  11. Write a shell script to generate a HTML.

  12. What is the difference between hard link and soft links ? Atleast 2 differences.
    Ans:
    1. About inode: In a hard link, inode nos will be same for both files, but will have different names. Soft link is a file which links to the original file (equivalent to shortcut in Windoze)

    2. About filesystem location: Hard links cannot reside on different partitions/filesystems (why? bcos same inode), soft links can point to files in any location.

  13. What are the types of files in Linux ? How do u know a file type ?
    Ans:
    d = directory
    l = symbolic link
    s = socket
    p = named pipe
    - = regular file
    c= character (unbuffered) device file special
    b=block (buffered) device file special

  14. How to Replicate different databases to different slaves?
    Ans: either one of the following (Ref: http://www.databasejournal.com/features/mysql/article.php/10897_3355201_2)
    1. Do the following settings in master (my.cnf)
        binlog-ignore-db=test
        binlog-ignore-db=scratch
        binlog-do-db=catalog
        binlog-do-db=users
        binlog-do-db=sessions
    2. Do the following settings in slave (my.cnf)
        replicate-do-db=catalog
        replicate-ignore-db=test
        replicate-ignore-db=scratch
        replicate-do-db=test
        replicate-do-db=sessions

  15. What is SOA in DNS
    Ans: Statement Of Authority

  16. What is Exit code for Ctrl + C
    Ans: 130

  17. What to do if i am getting error "passwd: Authentication token manipulation error" while updating the root password
    Ans: chattr -i /etc/shadow

  18. What Could happen if /sys directory is not there?
    Ans: Your system might say "Couldnt open //dev/tty3" n/w wont be start. And system also gives error like "comp init: Id "c2" respawning too fast: disabled for 5 minutes"

  19. What to do if dh -h gives "df: cannot read table of mounted file systems: Is a directory"
    Ans: /etc/mtab is the file. check if there if something wrong with it. This error mostly come when /etc/mtab is the directory not the file. Delete the /etc/mtab and do "mount -a" this will resolve your issue.

  20. What is the difference between "/etc/bashrc" and "/etc/profile"
    Ans: The global /etc/profile and your own local  ~/.bash_profile are read when the shell is invoked as an interactive login shell, for example when you open a remote terminal session to someone else's machine, or when you log into your own machine without X Windows running, or when you hit ctrl-alt-F1 from X Windows to start a virtual terminal session.

    The global /etc/bashrc (if it exists) and your own local  ~/.bashrc is read when the shell is invoked as an interactive non-login shell, for example when you open up a terminal window in Gnome or KDE.

  21. How do I print the line in between 25 to 50 from abc.txt which is of 100 lines in it.
    Ans: tail -n +25 abc.txt | head -n 25