grep cheat sheet
------------------
-i : ignore case
-w : Match the exact word
-A n : displays n lines after the match
-B n : displays n lines before the match
-C n : displays n lines on both sides of the match
-v : inverting the match
-e : for including multiple matches ( extending the match)
-c : counting the number of match
-l : displays only the file name of the match
-o : displays only the matched string
-b : displays the position of the match in the file
-n : line number will be displayed along with the match
Monday, April 13, 2009
Sunday, April 12, 2009
Timestamp with history
$ history
can be used to retrive the history of commands. It may be beneficial to display the timestamp along with the command for auditing purpose. HISTTIMEFORMAT variable can be used to achive the purpose
$ export HISTTIMEFORMAT=’%F %T ‘
Now the out put of the 'history' will be similer to this
Include the variable in your appropriate shell initialization file to make it permanent.
Thursday, April 2, 2009
Customise vi/vim - I
Correcting spelling mistakes automatically
------------------------------------------------
You can customise vi/vim according to your requirement using the ~/.vimrc file. You can even make vim learn the spellings of words also.
Suppose, you identified that usually commint some typoes ( teh for the, for example). We will see how to teach vi/vim to correct these mistakes automatically.
Open the file ~/.virmrc file and key in the contents as below and save the file.
iab teh the
The syntax is as follows.
ia incorrect_word correct_word
A plug-in for vim is available from http://www.vim.org/ , which is actually a collection of common mistakes we make, it is quite big repository which we can make use of.
Installing the autocorrect.tar plug-in
------------------------------------------
wget -O autocorrect.tar http://www.vim.org/scripts/download_script.php?src_id=9900
$ tar xf autocorrect.tar
Edit the ~/.vimrc file and key in the contents as below
$ vi ~/.vimrc
:source ~/autocorrect.vim
Note: If you dont want the auto correction permenently, you can add the source while in a vim session as below
:source
If you want to temporarly stop abbreviation for a word, you can use ' : uab teh' while in vim
:uab teh
------------------------------------------------
You can customise vi/vim according to your requirement using the ~/.vimrc file. You can even make vim learn the spellings of words also.
Suppose, you identified that usually commint some typoes ( teh for the, for example). We will see how to teach vi/vim to correct these mistakes automatically.
Open the file ~/.virmrc file and key in the contents as below and save the file.
iab teh the
The syntax is as follows.
ia incorrect_word correct_word
A plug-in for vim is available from http://www.vim.org/ , which is actually a collection of common mistakes we make, it is quite big repository which we can make use of.
Installing the autocorrect.tar plug-in
------------------------------------------
wget -O autocorrect.tar http://www.vim.org/scripts/download_script.php?src_id=9900
$ tar xf autocorrect.tar
Edit the ~/.vimrc file and key in the contents as below
$ vi ~/.vimrc
:source ~/autocorrect.vim
Note: If you dont want the auto correction permenently, you can add the source while in a vim session as below
:source
If you want to temporarly stop abbreviation for a word, you can use ' : uab teh' while in vim
:uab teh
Tuesday, March 31, 2009
Directory stack
Navigating directories using dirs, pushd and popd
Stack is a temporary data storage based on LIFO. The last item you push to stack, will be the first item you pop out.
we need pushd, popd and dirs to play around with stack
pushd: pushes or adds the directory to the directory stack
popd: pops or removes the directory from the directory stack (last in first out LIFO)
dirs: displays the contents of the stack
Directory stack can be really usful if you need to navigate to some directories which is very lengthy and you need to do it very often.
/tmp/very/long/directory/structure/that/is/too/deep
/tmp/hard/to/navigate/this/directory/structure
/some/structure/which/i/donot/prefer/navigating/often
Let us take the sample directory structures given above.
One way to make the navigation easy if you have to do it requenty is to set aliases, as given below
$ alias godeep="cd /tmp/very/long/directory/structure/that/is/too/deep"
OR, you can make use of the the directory stack.
The dirs command list the contents of the directory stack. The first entry it shows is not the contents, but the current directory. In this case the stack is empty.
$ cd /tmp/very/long/directory/structure/that/is/too/deep
$ pushd .
$ cd /some/structure/which/i/donot/prefer/navigating/often
$ pushd .
$ cd /some/structure/which/i/donot/prefer/navigating/often
$ pushd .
The out put of the dirs command will be as follows,
If you want to navigate to the third directory issue the following command
$ cd `dirs +3`
To remove the element from the stack issue the popd command as follows
$ popd
Wednesday, March 25, 2009
Running jobs in background
When you login to the linux machine, the shell creates three I/O channels that will be used by all the processes spawned from that shell. The I/O channels are stdin (standard input), stdout (standard output) and stderr (standard error).
Jobs can be put into background by using ^z and 'bg' commands. These job will be using the three I/O channels which we discussed above.
Once you log out from the shell those I/O channels are destroyed even though they are used by the job running in the background. The operating system will inteligently reassign the I/O channels to '/dev/null', means that all the output is dumped to the endless pit, and the jobs will not be shown in the jobs list, available while using the 'jobs' command , and also you will not have any trace of the process (will not dump the output to the console) even though it shows up in the process list 'ps -elf'.
To have a better idea about the process running in the background, start the process in the background using 'nohup'.
eg: $ nohup tail -f /var/log/messages > message.out &
$ tail -f message.out
OR, you can use of the 'screen' command as discussed some where in this blog.
Jobs can be put into background by using ^z and 'bg' commands. These job will be using the three I/O channels which we discussed above.
Once you log out from the shell those I/O channels are destroyed even though they are used by the job running in the background. The operating system will inteligently reassign the I/O channels to '/dev/null', means that all the output is dumped to the endless pit, and the jobs will not be shown in the jobs list, available while using the 'jobs' command , and also you will not have any trace of the process (will not dump the output to the console) even though it shows up in the process list 'ps -elf'.
To have a better idea about the process running in the background, start the process in the background using 'nohup'.
eg: $ nohup tail -f /var/log/messages > message.out &
$ tail -f message.out
OR, you can use of the 'screen' command as discussed some where in this blog.
Wednesday, March 18, 2009
Managing multiple windows with screen
Screen is really helpfull while administering remote servers using ssh, insted of opening new ssh sessions for each activity, you can make use of screen to manage the windows for you. It is very useful while you have to do multiple tasks in different windows.
To start screen
# screen
A new shell will be opened by screen, i which you can have multiple wiindows.
To start a new window
# Ctr+A c
Navigation between windows
# Ctr+A n - To go to the next window
# Ctr+A p - To go to the previous window
To detach the screen
# Ctr+A d or
# screen -d
( use exit of ^d to exit from screen, if you detact from screen the windows and session will be saved, so that you can resume from where you have stopped)
To list the detached screens
# screen -ls
To reattach a dettached screen
# screen -r
Have a nice screen ... ing
Tuesday, March 17, 2009
Monitoring Users and their activities
whowatch:-
To monitor the users and their activities as well as to manage the process.
It also provides a 'top' like view to manage the processess.
To monitor the users and their activities as well as to manage the process.
It also provides a 'top' like view to manage the processess.
Monday, March 2, 2009
sar System Activity Reporter
Identifying the bottleneck and fine tuning the system is one of the most important activities which we need to undertake as system administers. SAR will be a very handy tool once you get familiarized to it.
Sadc (system activity data collector) is the program that gathers performance data. It pulls its data out of the virtual /proc filesystem, then it saves the data in a file (one per day) named /var/log/sa/saDD where DD is the day of the month.
Two shell scripts from the sysstat package control how the data collector is run. The first script, sa1, controls how often data is collected, while sa2 creates summary reports (one per day) in /var/log/sa/sarDD. Both scripts are run from cron. In the default configuration, data is collected every 10 minutes and summarized just before midnight
cat /etc/cron.d/sysstat
----------------------
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1
# generate a daily summary of process accounting at 23:5353 23
* * * root /usr/lib/sa/sa2 -A
If the daily summary reports created by the sa2 script are not enough, you can create your own custom reports using sar. The sar program reads data from the current daily data file unless you specify otherwise. To have sar read a particular data file, use the -f /var/log/sa/saDD option. You can select multiple files by using multiple -f options. Since many of sar's reports are lengthy, you may want to pipe the output to a file.
Sar comes as part of 'sysstat' package in linux. First thing you need to do is to make sure that sysstat package is installed in you machine. It may not get installed along with the default packages.
Sysstat toolkit contains other tuning tools like
- iostat
- mpstat
rpm -qa grep sysstat
if not installed, install it....!
yum install systat
rpm -ql sysstat
if not installed, install it....!
yum install systat
rpm -ql sysstat
Sadc (system activity data collector) is the program that gathers performance data. It pulls its data out of the virtual /proc filesystem, then it saves the data in a file (one per day) named /var/log/sa/saDD where DD is the day of the month.
Two shell scripts from the sysstat package control how the data collector is run. The first script, sa1, controls how often data is collected, while sa2 creates summary reports (one per day) in /var/log/sa/sarDD. Both scripts are run from cron. In the default configuration, data is collected every 10 minutes and summarized just before midnight
cat /etc/cron.d/sysstat
----------------------
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1
# generate a daily summary of process accounting at 23:5353 23
* * * root /usr/lib/sa/sa2 -A
If the daily summary reports created by the sa2 script are not enough, you can create your own custom reports using sar. The sar program reads data from the current daily data file unless you specify otherwise. To have sar read a particular data file, use the -f /var/log/sa/saDD option. You can select multiple files by using multiple -f options. Since many of sar's reports are lengthy, you may want to pipe the output to a file.
Output of sar
Commonly Used switches
- -B To check the kernal paging performance
- -n DEV option tells sar to generate a report that shows the number of packets and bytes sent and received for each interface
- -W swapping statistics
- -q queueing statistics
- -d statistics about block devices
- -r shows the free memory and swap over time
To have the statistics about the current state of the system, issue the command as below
sar 2 10
The above command provides statistics of system activity at an interval of 2 seconds for 10 times
...... All the best........
Sunday, February 22, 2009
Ugrade AIX 5.2 to 5.3........
Hi,
I just want to upgrade my AIX 5.2-09-00 to 5.3-00-00, from where i can download 5.3 filesets? is it possible to do through smit(Update_all).???
I just want to upgrade my AIX 5.2-09-00 to 5.3-00-00, from where i can download 5.3 filesets? is it possible to do through smit(Update_all).???
Saturday, February 14, 2009
Migration tool for mail
Trying to migrate all the folders in inboxes to another server? try imapsync
http://freshmeat.net/projects/imapsync/
http://freshmeat.net/projects/imapsync/
Monday, January 19, 2009
Installing Oracle + PHP + apache
Here is a good link from oracle...
http://www.oracle.com/technology/tech/php/htdocs/inst_php_apache_linux.html
http://www.oracle.com/technology/tech/php/htdocs/inst_php_apache_linux.html
Subscribe to:
Posts (Atom)