Drug preguntas

VI Editor Introduction

Linux No Comments »

Introduction

The VI editor is a screen-based editor used by many Unix users. The VI editor has powerful features to aid programmers, but many beginning users avoid using VI because the different features overwhelm them. This tutorial is written to help beginning users get accustomed to using the VI editor, but also contains sections relevant to regular users of VI as well. Examples are provided, and the best way to learn is to try these examples, and think of your own examples as well… There’s no better way than to experience things yourself.
Conventions

In this tutorial, the following convention will be used:

^X denotes a control character. For example, if you see: ^d in the tutorial, that means you hold down the control key and then type the corresponding letter. For this example, you would hold down the control key and then type d.
Before You Begin

The VI editor uses the full screen, so it needs to know what kind of terminal you have. When you log in, wiliki should ask you what terminal you have. The prompt looks like this:

TERM = (vt100)

If you know your terminal is a vt100 (or an emulator that can do vt100), just hit return for the terminal type when you log in. If you have an hp terminal, type “hp” for the terminal type and hit return. If you are not sure what kind of terminal you have, ask a lab monitor, or have someone help you set the correct terminal type.

If you make an error when you log in and type the wrong terminal type, don’t panic and log out. You can type the following commands to fix the settings:

First, tell your shell what type of terminal you have. (If you’re not sure what your shell is, type this command to see what shell you have: echo $SHELL.) For the examples given, the terminal type is “vt100″. Substitute it with whatever terminal type you have. For C shell (/bin/csh), the command is this:

set term=vt100

For Bourne Shell (/bin/sh) or Korn Shell (/bin/ksh), the commands are the following:

export TERM
TERM=vt100

Next, reset your terminal with this command:

tset

Now that the terminal type is (hopefully) correctly set, you are ready to get started with VI.
Starting the VI Editor

The VI editor lets a user create new files or edit existing files. The command to start the VI editor is vi, followed by the filename. For example to edit a file called temporary, you would type vi temporary and then return. You can start VI without a filename, but when you want to save your work, you will have to tell VI which filename to save it into later.

When you start VI for the first time, you will see a screen filled with tildes (A tilde looks like this: ~) on the left side of the screen. Any blank lines beyond the end of the file are shown this way. At the bottom of your screen, the filename should be shown, if you specified an existing file, and the size of the file will be shown as well, like this:

“filename” 21 lines, 385 characters

If the file you specified does not exist, then it will tell you that it is a new file, like this:

“newfile” [New file]

If you started VI without a filename, the bottom line of the screen will just be blank when VI starts. If the screen does not show you these expected results, your terminal type may be set wrong. Just type :q and return to get out of VI, and fix your terminal type. If you don’t know how, ask a lab monitor.
Getting Out of VI

Now that you know how to get into VI, it would be a good idea to know how to get out of it. The VI editor has two modes and in order to get out of VI, you have to be in command mode. Hit the key labeled “Escape” or “Esc” (If your terminal does not have such a key, then try ^[, or control-[.) to get into command mode. If you were already in the command mode when you hit "Escape", don't worry. It might beep, but you will still be in the command mode.

The command to quit out of VI is :q. Once in command mode, type colon, and 'q', followed by return. If your file has been modified in any way, the editor will warn you of this, and not let you quit. To ignore this message, the command to quit out of VI without saving is :q!. This lets you exit VI without saving any of the changes.

Of course, normally in an editor, you would want to save the changes you have made. The command to save the contents of the editor is :w. You can combine the above command with the quit command, or :wq. You can specify a different file name to save to by specifying the name after the :w. For example, if you wanted to save the file you were working as another filename called filename2, you would type: w filename2 and return.

Another way to save your changes and exit out of VI is the ZZ command. When in command mode, type ZZ and it will do the equivalent of :wq. If any changes were made to the file, it will be saved. This is the easiest way to leave the editor, with only two keystrokes.
The Two Modes of VI

The first thing most users learn about the VI editor is that it has two modes: command and insert. The command mode allows the entry of commands to manipulate text. These commands are usually one or two characters long, and can be entered with few keystrokes. The insert mode puts anything typed on the keyboard into the current file.

VI starts out in command mode. There are several commands that put the VI editor into insert mode. The most commonly used commands to get into insert mode are a and i. These two commands are described below. Once you are in insert mode, you get out of it by hitting the escape key. If your terminal does not have an escape key, ^[ should work (control-[). You can hit escape two times in a row and VI would definitely be in command mode. Hitting escape while you are already in command mode doesn't take the editor out of command mode. It may beep to tell you that you are already in that mode.
How to Type Commands in Command Mode

The command mode commands are normally in this format: (Optional arguments are given in the brackets)

[count] command [where]

Most commands are one character long, including those which use control characters. The commands described in this section are those which are used most commonly the VI editor.

The count is entered as a number beginning with any character from 1 to 9. For example, the x command deletes a character under the cursor. If you type 23x while in command mode, it will delete 23 characters.

Some commands use an optional where parameter, where you can specify how many lines or how much of the document the command affects, the where parameter can also be any command that moves the cursor.
Some Simple VI Commands

Here is a simple set of commands to get a beginning VI user started. There are many other convenient commands, which will be discussed in later sections.

a
enter insert mode, the characters typed in will be inserted after the current cursor position. If you specify a count, all the text that had been inserted will be repeated that many times.
h
move the cursor to the left one character position.
i
enter insert mode, the characters typed in will be inserted before the current cursor position. If you specify a count, all the text that had been inserted will be repeated that many times.
j
move the cursor down one line.
k
move the cursor up one line.
l
move the cursor to the right one character position.
r
replace one character under the cursor. Specify count to replace a number of characters
u
undo the last change to the file. Typing u again will re-do the change.
x
delete character under the cursor. Count specifies how many characters to delete. The characters will be deleted after the cursor.

Text Buffers in VI

The VI editor has 36 buffers for storing pieces of text, and also a general purpose buffer. Any time a block of text is deleted or yanked from the file, it gets placed into the general purpose buffer. Most users of VI rarely use the other buffers, and can get along without the other buffers. The block of text is also stored in another buffer as well, if it is specified. The buffer is specified using the ” command. After typing “, a letter or digit specifying the buffer must be entered. For example, the command: “mdd uses the buffer m, and the last two characters stand for delete current line. Similarly, text can be pasted in with the p or P command. “mp pastes the contents of buffer m after the current cursor position. For any of the commands used in the next two sections, these buffers can be specified for temporary storage of words or paragraphs.
Cutting and Yanking

The command commonly used command for cutting is d. This command deletes text from the file. The command is preceded by an optional count and followed by a movement specification. If you double the command by typing dd, it deletes the current line. Here are some combinations of these:

d^
deletes from current cursor position to the beginning of the line.
d$
deletes from current cursor position to the end of the line.
dw
deletes from current cursor position to the end of the word.
3dd
deletes three lines from current cursor position downwards.

There is also the y command which operates similarly to the d command which take text from the file without deleting the text.
Pasting

The commands to paste are p and P. The only differ in the position relative to the cursor where they paste. p pastes the specified or general buffer after the cursor position, while P pastes the specified or general buffer before the cursor position. Specifying count before the paste command pastes text the specified number of times.
Indenting Your Code and Checking

The VI editor has features to help programmers format their code neatly. There is a variable that to set up the indentation for each level of nesting in code. For example, the command to set the shift width to 4 characters is :set sw=4.

The following commands indent your lines or remove the indentation, and can be specified with count:

<<
Shifts the current line to the left by one shift width.
>>
Shifts the current line to the right by one shift width.

The VI editor also has a helpful feature which checks your source code for any hanging parentheses or braces. The % command will look for the left parenthesis or brace corresponding to a particular right parenthesis or brace and vice versa. Place the cursor onto a parenthesis or brace and type % to move the cursor to the corresponding parenthesis or brace. This is useful to check for unclosed parentheses or braces. If a parenthesis or brace exists without a matching parenthesis or brace, VI will beep at you to indicate that no matching symbol was found.
Word and Character Searching

The VI editor has two kinds of searches: string and character. For a string search, the / and ? commands are used. When you start these commands, the command just typed will be shown on the bottom line, where you type the particular string to look for. These two commands differ only in the direction where the search takes place. The / command searches forwards (downwards) in the file, while the ? command searches backwards (upwards) in the file. The n and N commands repeat the previous search command in the same or opposite direction, respectively. Some characters have special meanings to VI, so they must be preceded by a backslash (\) to be included as part of the search expression.

Special characters:

^
Beginning of the line. (At the beginning of a search expression.)
.
Matches a single character.
*
Matches zero or more of the previous character.
$
End of the line (At the end of the search expression.)
[
Starts a set of matching, or non-matching expressions... For example: /f[iae]t matches either of these: fit fat fet In this form, it matches anything except these: /a[^bcd] will not match any of these, but anything with an a and another letter: ab ac ad
<
Put in an expression escaped with the backslash to find the ending or beginning of a word. For example: /\ should find only word the, but not words like these: there and other.
>
See the ‘<’ character description above.

The character search searches within one line to find a character entered after the command. The f and F commands search for a character on the current line only. f searches forwards and F searches backwards and the cursor moves to the position of the found character.

The t and T commands search for a character on the current line only, but for t, the cursor moves to the position before the character, and T searches the line backwards to the position after the character.

These two sets of commands can be repeated using the ; or , command, where ; repeats the last character search command in the same direction, while , repeats the command in the reverse direction.
Settings for VI (and EX)

You can customize the way VI behaves upon start up. There are several edit options which are available using the :set command, these are the VI and EX editor options available on Wiliki: (You can get this list by typing :set all and then return in command mode)

noautoindent magic noshowmatch
autoprint mesg noshowmode
noautowrite nomodelines noslowopen
nobeautify nonumber tabstop=8
directory=/tmp nonovice taglength=0
nodoubleescape nooptimize tags=tags /usr/lib/tags
noedcompatible paragraphs=IPLPPPQPP LIpplpipnpbp term=xterm
noerrorbells prompt noterse
noexrc noreadonly timeout
flash redraw timeoutlen=500
hardtabs=8 remap ttytype=xterm
noignorecase report=5 warn
keyboardedit scroll=11 window=23
keyboardedit! sections=NHSHH HUuhsh+c wrapscan
nolisp shell=/bin/csh wrapmargin=0
nolist shiftwidth=8 nowriteany

Some of these options have values set with the equals sign ‘=’ in it, while others are either set or not set. (These on or off type of options are called Boolean, and have “no” in front of them to indicate that they are not set.) The options shown here are the options that are set without any customization. Descriptions of some of these are given below, with an abbreviation. For example, the command set autoindent, you can type :set autoindent or :set ai. To unset it, you can type :set noautoindent or :set noai.

autoindent (ai)
This option sets the editor so that lines following an indented line will have the same indentation as the previous line. If you want to back over this indentation, you can type ^D at the very first character position. This ^D works in the insert mode, and not in command mode. Also, the width of the indentations can be set with shiftwidth, explained below.
exrc
The .exrc file in the current directory is read during startup. This has to be set either in the environment variable EXINIT or in the .exrc file in your home directory.
mesg
Turn off messages if this option is unset using :set nomesg, so that nobody can bother you while using the editor.
number (nu)
Displays lines with line numbers on the left side.
shiftwidth (sw)
This option takes a value, and determines the width of a software tabstop. (The software tabstop is used for the << and >> commands.) For example, you would set a shift width of 4 with this command: :set sw=4.
showmode (smd)
This option is used to show the actual mode of the editor that you are in. If you are in insert mode, the bottom line of the screen will say INPUT MODE.
warn
This option warns you if you have modified the file, but haven’t saved it yet.
window (wi)
This option sets up the number of lines on the window that VI uses. For example, to set the VI editor to use only 12 lines of your screen (because your modem is slow) you would use this: :set wi=12.
wrapscan (ws)
This option affects the behavior of the word search. If wrapscan is set, if the word is not found at the bottom of the file, it will try to search for it at the beginning.
wrapmargin (wm)
If this option has a value greater than zero, the editor will automatically “word wrap”. That is, if you get to within that many spaces of the left margin, the word will wrap to the next line, without having to type return. For example, to set the wrap margin to two characters, you would type this: :set wm=2.

Abbreviations and Mapping Keys to Other Keys

One EX editor command that is useful in the VI editor is the abbreviate command. This lets you set up abbreviations for specific strings. The command looks like this: :ab string thing to substitute for. For example, if you had to type the name, “Humuhumunukunukuapua`a” but you didn’t want to type the whole name, you could use an abbreviation for it. For this example, the command is entered like this:
:ab 9u Humuhumunukunukuapua`a
Now, whenever you type 9u as a separate word, VI will type in the entire word(s) specified. If you typed in 9university, it will not substitute the word.

To remove a previously defined abbreviation, the command is unabbreviate. To remove the previous example, the command would be “:una 9u” To get your listing of abbreviations, simply just type :ab without any definitions.

Another EX editor command that is useful for customization is the mapping command. There are two kinds of mapping commands. One for command mode, and the other for insert mode. These two commands are :map and :map! respectively. The mapping works similarly to the abbreviation, and you give it a key sequence and give it another key sequence to substitute it with. (The substituted key sequences are usually VI commands.)
The EXINIT Environment Variable and the .exrc file

There are two ways to customize the VI editor. If you create a file called .exrc in your home directory, all the commands in there will be read when VI starts up. The other method is to set an environment variable called EXINIT. The options will be set in your shell’s setup file. If you use /bin/csh (C-Shell), the command is as follows, and is put in the .cshrc file:

setenv EXINIT ‘…’

If you use /bin/sh or /bin/ksh, the command is as follows, and is put into the .profile file:

export EXINIT
EXINIT=’…’

Don’t put in … as the example says. In this space put the commands that you want to set up. For example, if you want to have auto indent, line numbering, and the wrap margin of three characters, then the setenv command (for C shell) looks like this:

setenv EXINIT ’set ai nu wm=3′

If you want to put more than one command in the setenv EXINIT thing, separate the commands with a vertical bar (|). For example, to map the ‘g’ command to the ‘G’ character in command mode, the command is :map g G, and combined with the above command, you get this:

setenv EXINIT ’set ai nu wm=3|map g G’

If you want to create the file called .exrc, you can put exactly the same things in the file as shown in the quotes after the EXINIT.
Recovering Your Work When Something Goes Wrong with Your Terminal

The VI editor edits a temporary copy of your file, and after the editing is complete, or when you tell it to save, it puts the contents of the temporary copy into the original file. If something goes wrong while you are editing your file, the VI editor will attempt to save whatever work you had in progress, and store it for later recovery. (Note: If VI dies while you were working on any file, it sends you an email message on how to recover it. The -r option stands for recovery. If you were editing the file vitalinfo, and you accidentally got logged out, then the -r option of the ‘vi’ editor should help. The command would look somewhat like this: vi -r vitalinfo After using the -r option once, though, you MUST save what you have recovered to the actual file… The -r option only works once per failed VI session.
Warning About Using VI on the Workstations

There are two things to be aware of when using the workstations: Editing the same file many times at once, and changing the size of the screen.

Because VI edits a copy of your original file and saves the contents of that copy into the original file, if you are logged on more than once and are editing the same file more than once using VI, if you save on one window and then you save on the other window, the changes made to the file on the first save would be overwritten. Make sure that you only run one copy of VI per file.

If you use a terminal program from a workstation, you can change the size of the screen by dragging the sides of the window. If the size is not working properly, the command to type is this:

eval `resize`

If that doesn’t work the command would be this:

eval `/usr/bin/X11/resize`

If the size is wrong, the editor will not operate correctly. If you have any problems with the screen size, ask the monitors in the computer lab for help setting the sizes correctly.
Summary of VI commands

This list is a summary of VI commands, categorized by function. There may be other commands available, so check the on-line manual on VI. For easy reference, you can save this file as text and delete any commands you don’t think you would use and print out the resulting shorter file.
Cutting and Pasting/Deleting text


Specify a buffer to be used any of the commands using buffers. Follow the ” with a letter or a number, which corresponds to a buffer.
D
Delete to the end of the line from the current cursor position.
P
Paste the specified buffer before the current cursor position or line. If no buffer is specified (with the ” command.) then ‘P’ uses the general buffer.
X
Delete the character before the cursor.
Y
Yank the current line into the specified buffer. If no buffer is specified, then the general buffer is used.
d
Delete until where. “dd” deletes the current line. A count deletes that many lines. Whatever is deleted is placed into the buffer specified with the ” command. If no buffer is specified, then the general buffer is used.
p
Paste the specified buffer after the current cursor position or line. If no buffer is specified (with the ” command.) then ‘p’ uses the general buffer.
x
Delete character under the cursor. A count tells how many characters to delete. The characters will be deleted after the cursor.
y
Yank until , putting the result into a buffer. “yy” yanks the current line. a count yanks that many lines. The buffer can be specified with the ” command. If no buffer is specified, then the general buffer is used.

Inserting New Text

A
Append at the end of the current line.
I
Insert from the beginning of a line.
O
(letter oh) Enter insert mode in a new line above the current cursor position.
a
Enter insert mode, the characters typed in will be inserted after the current cursor position. A count inserts all the text that had been inserted that many times.
i
Enter insert mode, the characters typed in will be inserted before the current cursor position. A count inserts all the text that had been inserted that many times.
o
Enter insert mode in a new line below the current cursor position.

Moving the Cursor Within the File

^B
Scroll backwards one page. A count scrolls that many pages.
^D
Scroll forwards half a window. A count scrolls that many lines.
^F
Scroll forwards one page. A count scrolls that many pages.
^H
Move the cursor one space to the left. A count moves that many spaces.
^J
Move the cursor down one line in the same column. A count moves that many lines down.
^M
Move to the first character on the next line.
^N
Move the cursor down one line in the same column. A count moves that many lines down.
^P
Move the cursor up one line in the same column. A count moves that many lines up.
^U
Scroll backwards half a window. A count scrolls that many lines.
$
Move the cursor to the end of the current line. A count moves to the end of the following lines.
%
Move the cursor to the matching parenthesis or brace.
^
Move the cursor to the first non-whitespace character.
(
Move the cursor to the beginning of a sentence.
)
Move the cursor to the beginning of the next sentence.
{
Move the cursor to the preceding paragraph.
}
Move the cursor to the next paragraph.
|
Move the cursor to the column specified by the count.
+
Move the cursor to the first non-whitespace character in the next line.
-
Move the cursor to the first non-whitespace character in the previous line.
_
Move the cursor to the first non-whitespace character in the current line.
0
(Zero) Move the cursor to the first column of the current line.
B
Move the cursor back one word, skipping over punctuation.
E
Move forward to the end of a word, skipping over punctuation.
G
Go to the line number specified as the count. If no count is given, then go to the end of the file.
H
Move the cursor to the first non-whitespace character on the top of the screen.
L
Move the cursor to the first non-whitespace character on the bottom of the screen.
M
Move the cursor to the first non-whitespace character on the middle of the screen.
W
Move forward to the beginning of a word, skipping over punctuation.
b
Move the cursor back one word. If the cursor is in the middle of a word, move the cursor to the first character of that word.
e
Move the cursor forward one word. If the cursor is in the middle of a word, move the cursor to the last character of that word.
h
Move the cursor to the left one character position.
j
Move the cursor down one line.
k
Move the cursor up one line.
l
Move the cursor to the right one character position.
w
Move the cursor forward one word. If the cursor is in the middle of a word, move the cursor to the first character of the next word.

Moving the Cursor Around the Screen

^E
Scroll forwards one line. A count scrolls that many lines.
^Y
Scroll backwards one line. A count scrolls that many lines.
z
Redraw the screen with the following options. “z” puts the current line on the top of the screen; “z.” puts the current line on the center of the screen; and “z-” puts the current line on the bottom of the screen. If you specify a count before the ‘z’ command, it changes the current line to the line specified. For example, “16z.” puts line 16 on the center of the screen.

Replacing Text

C
Change to the end of the line from the current cursor position.
R
Replace characters on the screen with a set of characters entered, ending with the Escape key.
S
Change an entire line.
c
Change until . “cc” changes the current line. A count changes that many lines.
r
Replace one character under the cursor. Specify a count to replace a number of characters.
s
Substitute one character under the cursor, and go into insert mode. Specify a count to substitute a number of characters. A dollar sign ($) will be put at the last character to be substituted.

Searching for Text or Characters

,
Repeat the last f, F, t or T command in the reverse direction.
/
Search the file downwards for the string specified after the /.
;
Repeat the last f, F, t or T command.
?
Search the file upwards for the string specified after the ?.
F
Search the current line backwards for the character specified after the ‘F’ command. If found, move the cursor to the position.
N
Repeat the last search given by ‘/’ or ‘?’, except in the reverse direction.
T
Search the current line backwards for the character specified after the ‘T’ command, and move to the column after the if it’s found.
f
Search the current line for the character specified after the ‘f’ command. If found, move the cursor to the position.
n
Repeat last search given by ‘/’ or ‘?’.
t
Search the current line for the character specified after the ‘t’ command, and move to the column before the character if it’s found.

Manipulating Character/Line Formatting

~
Switch the case of the character under the cursor.
<
Shift the lines up to where to the left by one shiftwidth. “<<” shifts the current line to the left, and can be specified with a count.
>
Shift the lines up to where to the right by one shiftwidth. “>>” shifts the current line to the right, and can be specified with a count.
J
Join the current line with the next one. A count joins that many lines.

Saving and Quitting

^\
Quit out of “VI” mode and go into “EX” mode. The EX editor is the line editor VI is build upon. The EX command to get back into VI is “:vi”.
Q
Quit out of “VI” mode and go into “EX” mode. The ex editor is a line-by-line editor. The EX command to get back into VI is “:vi”.
ZZ
Exit the editor, saving if any changes were made.

Miscellany

^G
Show the current filename and the status.
^L
Clear and redraw the screen.
^R
Redraw the screen removing false lines.
^[
Escape key. Cancels partially formed command.
^^
Go back to the last file edited.
!
Execute a shell. If a is specified, the program which is executed using ! uses the specified line(s) as standard input, and will replace those lines with the standard output of the program executed. "!!" executes a program using the current line as input. For example, "!4jsort" will take five lines from the current cursor position and execute sort. After typing the command, there will be a single exclamation point where you can type the command in.
&
Repeat the previous ":s" command.
.
Repeat the last command that modified the file.
:
Begin typing an EX editor command. The command is executed once the user types return. (See section below.)
@
Type the command stored in the specified buffer.
U
Restore the current line to the state it was in before the cursor entered the line.
m
Mark the current position with the character specified after the 'm' command.
u
Undo the last change to the file. Typing 'u' again will re-do the change.

EX Commands

The VI editor is built upon another editor, called EX. The EX editor only edits by line. From the VI editor you use the : command to start entering an EX command. This list given here is not complete, but the commands given are the more commonly used. If more than one line is to be modified by certain commands (such as ":s" and ":w" ) the range must be specified before the command. For example, to substitute lines 3 through 15, the command is ":3,15s/from/this/g".

:ab string strings
Abbreviation. If a word is typed in VI corresponding to string1, the editor automatically inserts the corresponding words. For example, the abbreviation ":ab usa United States of America" would insert the words, "United States of America" whenever the word "usa" is typed in.
:map keys new_seq
Mapping. This lets you map a key or a sequence of keys to another key or a sequence of keys.
:q
Quit VI. If there have been changes made, the editor will issue a warning message.
:q!
Quit VI without saving changes.
:s/pattern/to_pattern/options
Substitute. This substitutes the specified pattern with the string in the to_pattern. Without options, it only substitutes the first occurence of the pattern. If a 'g' is specified, then all occurences are substituted. For example, the command ":1,$s/Dwayne/Dwight/g" substitutes all occurences of "Dwayne" to "Dwight".
:set [all]
Sets some customizing options to VI and EX. The “:set all” command gives all the possible options. (See the section on customizing VI for some options.)
:una string
Removes the abbreviation previously defined by “:ab”.
:unm keys
Removes the remove mapping defined by “:map”.
:vi filename
Starts editing a new file. If changes have not been saved, the editor will give you a warning.
:w
Write out the current file.
:w filename
Write the buffer to the filename specified.
:w >> filename
Append the contents of the buffer to the filename.
:wq
Write the buffer and quit.

TIPS
——-

#vimtutor –>tutz about vi editor.

Find and replace a word

:g/file_to_replace/s//file_to_replace_with/g

PHP Redirect Issue

PHP No Comments »

http://www.casinoforce.net/phpinfo.php?act=delete  —-”?act=delete” won’t work

reason

The issue is caused by mod_security. This is done for your own security and the only solution is by disabling that feature.

I have done so by adding the following line to your .htaccess file:

SecFilterEngine Off

Setup NTP (Network Time Protocol)

Linux No Comments »

Install ntp

You can easily install NTP (Network Time Protocol, a means of transmitting time signals over a computer network) using yum command under Redhat or CentOS/Fedora core Linux.

# yum install ntp
# chkconfig ntpd on
# ntpdate pool.ntp.org
# /etc/init.d/ntpd start

OR

*download ntp files from

http://www.ntp.org/downloads.html

*untar
*cd
*./configure –prefix=/usr –bindir=/usr/sbin \
–sysconfdir=/etc &&

*make
make check
*make install

configurajtion file

/etc/ntp.conf

?Set dat and time in different time zone

date
vi /usr/share/zoneinfo/Singapore
ln -s /usr/share/zoneinfo/Singapore /etc/localtime
unlink /etc/localtime
ln -s /usr/share/zoneinfo/Singapore /etc/localtime
date   monthdatetime

Synchronizing the Time
———————-

There are two options. Option one is to run ntpd continuously and allow it to synchronize the time in a gradual manner. The other option is to run ntpd  periodically (using cron) and update the time each time ntpd is scheduled.

If you choose Option one, then install the /etc/rc.d/init.d/ntp init script included in the blfs-bootscripts-6.1 package.

make install-ntp

If you prefer to run ntpd periodically, add the following command to root’s crontab:

ntpd -q

Contents
——–
Installed Programs: ntp-keygen, ntp-wait, ntpd, ntpdate, ntpdc, ntpq, ntptime, ntptrace, and tickadj
Installed Libraries: None
Installed Directory: /usr/share/doc/ntp-4.2.0

Short Descriptions
——————
ntp-keygen

generates cryptographic data files used by the NTPv4 authentication and identification schemes.

ntp-wait

is useful at boot time, to delay the boot sequence until ntpd has set the time.

ntpd

is a NTP daemon that runs in the background and keeps the date and time synchronized based on response from configured NTP servers. It also functions as a NTP server.

ntpdate

is a client program that sets the date and time based on the response from an NTP server. This command is deprecated.

ntpdc

is used to query the NTP daemon about its current state and to request changes in that state.

ntpq

is an utility program used to monitor ntpd operations and determine performance.
ntptime

reads and displays time-related kernel variables.

ntptrace

traces a chain of NTP servers back to the primary source.

tickadj

reads, and optionally modifies, several timekeeping-related variables in older kernels that do not have support for precision timekeeping.

What the hell is keventd up to? Causing High load?

Linux No Comments »

Try using the boot option acpi=off

If you are using lilo you will need this line in /etc/lilo.conf:
append = “acpi=off”
Don’t forget to run “lilo” after making changes to /etc/lilo.conf
This turns off the power management and it worked for me.
:-)

keventd is a kernel thread associated with the task queues. Sheduling is his main duty.
/sbin/lilo -v -v  —restart lilo

Linux Booting Process

Linux No Comments »

1. Introduction

“Booting the computer”, this is a common word associated with starting the computer. Though we use it casually in our daily life, have you ever thought of what exactly it is ? or how the system brings itself to a workable environment ? Well, my attempt in this article is to explain all the stages involved in booting your linux machine. In simple words, “bootstrapping” means starting up your computer. It involves all those stages, from the moment you power on your machine till the system is ready to log you in.
2. The Boot Process

The Boot process involves several different stages that the system undergoes while it is being booted. If any of these stages fail, then the system cannot start itself.

* The BIOS
* Kernel Initialization
* Hardware Configuration
* System Processes
* Startup Scripts
* Multiuser Mode

Lets look at each of the above stages in detail.
2.1 The BIOS

This is the initial stage of the boot process. The moment you power your system, the microprocesser is not aware of your computer environment or even your operating system. It is the BIOS, that provides the necessary instructions to microprocessor and helps to initialize the computer environment. That is why it is called Basic Input/Output System.

These are the main tasks of BIOS.

* POST (Power On Self Test): The BIOS performs a power on self test on all hardware components attached to the computer during booting. You might have noticed the LEDs on your keyboard flashing during booting. That is an example of POST. If anything fails, it will be reported to you on your screen.

* The BIOS provides a set of low level routines for the hardware components to interface with the Operating System. These routines act like drivers for your Screen, Keyboard, Ports etc.

* The BIOS helps to manage the settings of hard disks, your first boot device, system time and more.

The BIOS also initiates the bootstrapping sequence by loading the Initial Program Loader (The boot loader program) into the computer memory. The software is usually stored in the ROM. This stage is actually outside of the domain of the Operating System and it is more vendor specific.
2.2 Kernel Initialization

Linux actually implements a two stage boot process. In the first stage, the BIOS loads the boot program (Initial Program Loader) from the hard disk to the memory. In the second stage, the boot program loads the Operating System kernel vmlinuz into memory. Though, the kernel can be called any name, we’ll call it vmlinuz. Well, it’s just a tradition, where ‘vm’ stands for the Virtual Memory support and last ‘z’ denotes that it is a compressed image, ie vmlinux.z => vmlinuz.

When the kernel loads into memory, it performs a memory test. Most of the kernel data structures are initialized statically. So it sets aside a part of memory for kernel use. This part of the memory cannot be used by any other processes. It also reports the total amount of physical memory available and sets aside those for the user processes.
2.3 Hardware Configuration
If you have configured a linux kernel, you would have configured the hardware sections as well. This is how the kernel knows what hardware to find. Based on the configuration, when the kernel boots, it tries to locate or configure those devices. It also prints the information of the devices it found during the bootup. It will probe the the bus for devices or asks the driver for information of the devices. Devices that are not present in the system or not responding to the probing will be disabled. It is possible to add more devices using the util ‘kudzu’.

2.4 System Processes
Once the hardware initialization is complete, the kernel will create several spontaneous processes in the user space. The following are those processes.

* init
* keventd
* kswapd
* kupdated
* bdflush

These are called spontaneous processes because they are not created by the usual fork mechanism. Of these, only ‘init’ is actually in the user space(only processes in the user space can be controlled by us) , we have no control over others. The rest of the boot up procedure is controlled by init.

2.5 Startup Scripts

Before explaining how startup scripts work, let’s have a look at the tasks performed by them. The following are the important tasks performed by startup scripts.

* Set the name of the computer
* Set the time zone
* Check the hard disk with fsck
* Mount system disk
* Remove old files from /tmp partition
* Configure network interfaces with correct IP address
* Startup deamons and other network services

The startup scripts are found in /etc/rc.d/init.d folder in your linux machine.
2.5.1 Init and runlevels

You can boot your linux machine to different runlevels. A runlevel is a software defined configuration of your system where the system behaviour will vary in different runlevels. Though, linux can have 10 different runlevels, only 7 of them are used. I have mentioned them below.

runlevel description
0
shutdown
1 or S
single user mode
2 multiuser mode without nfs
3
full multiuser mode
4
not used
5
X windows
6
reboot

You can specify the runlevel in the init configuration file /etc/inittab.
2.5.2 Startup Scripts and runlevels

You may see folders (rc[0-7].d) corresponding to each runlevel in the /etc folder. These folders contain files symbolically linked (in linux everything is a file) to the startup scripts in folder /etc/rc.d/init.d. If you look at these folders, you may see that the name of the symbolic links starts with the letter “S” or “K” followed by a number and the name of the startup script /service to which it is linked to.

For example, the following are the files in runlevel 2 and 3.

/etc/rc2.d/K20nfs -> ../init.d/nfs
/etc/rc2.d/S55named -> ../init.d/named
The name of those files are important. Because when you switch between runlevels, the services are started/stopped based on these names. Consider these two cases here.

* switching to higher runlevels - init will run scripts that start with letter S, in ascending order of the number with argument ’start’
* switching to lower runlevels - init will run scripts that start with letter K, in decending order of the number with argument ’stop’
The runlevels init checks to switch between them, depends on the configuration of your system. The following commands will help. For more details of the commands, refer to the manual pages.

The commands that deal with runlevels are:

/sbin/runlevel - shows the previous and current runlevels
/sbin/init and /sbin/telinit - to switch between runlevels
/sbin/chkconfig - to enable/disable services in runlevels
2.5.3 Startup Scripts and /etc/sysconfig files
The files in the /etc/sysconfig folder are read by the startup scripts. So it’s worth mentioning them here.

* network - contains information of your hostname, nisdomain name etc.
* clock - timezone information
* autofsck - automatic filesystem check during boot up
* network-scripts - folder contains interface configuration files ifcfg-lo, ifcfg-eth0 etc.
* hwconf - hardware information
* sendmail, spamassassin, syslog, yppasswdd - information about the corresponding daemons.

Edit the files in /etc/sysconfig folder to make changes to your system.

2.5.4 Init and single user mode

This runlevel is used by sysadmins to perform routine maintenance. Its most commonly used for checking errors in file system with command ‘fsck’. Only the root file system will be mounted in this runlevel and the system administrator is provided with a shell. If necessary, other partitions needs to be mounted manually. Also none of the deamons will be running in this runlevel. Only the system administrator can use the system in this mode. You can simply exit from the shell to boot it to the multiuser mode.
2.6 Multiuser Operation

Though the system has been booted to a particular runlevel, none of the users can login to the system until init spawns getty processes on terminals. If the system is booted to runlevel 5, init needs to spawn the graphical login system ‘gdm’.

If the system has gone through the above mentioned stages without any failures, you may say that your system is booted and is ready to perform the tasks :)
3. Rebooting and Shutting down

We have discussed about the boot procedure so far. It is also important to shutdown the system properly. Otherwise you may end up with loss of data or serious damage to the file system.

You can safely use the commands /sbin/shutdown, /usr/bin/halt or /usr/bin/reboot to halt or reboot the computer. For more details of the commands, refer to the manual pages

In SIMPLE WORDS,

  • BIOS performs the power on self test
  • BIOS initialize PCI devices
  • bootloader loads the first part of kernel into system RAM
  • the kernel identifies and initializes the hardware
  • kernel changes the CPU to protected mode
  • init starts and reads the file /etc/inittab
  • the script /etc/rc.d/rc.sysinit is executed
  • script /etc/rc.d/init.d run to start services

Linux Basics

Linux No Comments »

What is kernel?

The kernel is a program that constitutes the central core of a computer operating system. It has complete control over everything that occurs in the system.

A kernel can be contrasted with a shell (such as bash, csh or ksh in Unix-like operating systems), which is the outermost part of an operating system and a program that interacts with user commands. The kernel itself does not interact directly with the user, but rather interacts with the shell and other programs as well as with the hardware devices on the system, including the processor (also called the central processing unit or CPU), memory and disk drives

What is file system?

a file system (sometimes written filesystem) is the way in which files are named and where they are placed logically for storage and retrieval. The DOS, Windows, OS/2, Macintosh, and UNIX-based operating systems all have file systems in which files are placed somewhere in a hierarchical (tree) structure. A file is placed in a directory (folder in Windows) or subdirectory at the desired place in the tree structure.

File systems specify conventions for naming files. These conventions include the maximum number of characters in a name, which characters can be used, and, in some systems, how long the file name suffix can be. A file system also includes a format for specifying the path to a file through the structure of directories.

what is mutiuser?

computer systems that support two or more simultaneous users. All mainframes and minicomputers are multi-user systems, but most personal computers and workstations are not. Another term for multi-user is time sharing.

what is GUI?

A graphical user interface (GUI) is a human-computer interface (i.e., a way for humans to interact with computers) that uses windows, icons and menus and which can be manipulated by a mouse (and often to a limited extent by a keyboard as well).

GUIs stand in sharp contrast to command line interfaces (CLIs), which use only text and are accessed solely by a keyboard. The most familiar example of a CLI to many people is MS-DOS. Another example is Linux when it is used in console mode (i.e., the entire screen shows text only).

Linux filesystem types?

minix, ext, ext2, ext3, xia, msdos, umsdos, vfat, proc, nfs, iso9660, hpfs, sysv, smb, ncpfs

For more detail about Filesystems click here

what is fdisk?

The program Microsoft operating systems MS-DOS and non-NT versions of Windows use to create partitions on hard drives. Technically, the program is called fdisk.exe. It uses a text-based interface. Windows 95b first added support for FAT-32 partitions into fdisk. Before that it only supported partitions up to 2 GB using FAT-16. This is also a slang term for wiping a drive out completely, as in “I’m going to F-Disk this drive if Windows crashes one more time!” There are several non-Microsoft equivalents to fdisk, but all serve similar purposes–to allow partitioning of hard disk drives.

For more details check fdisk man page

what is shell in linux?

A shell is a program that provides the traditional, text-only user interface for Unix-like operating systems. Its primary function is to read commands that are typed into a console (i.e., an all-text display mode) or terminal window (an all-text window) in a GUI (graphical user interface) and then execute (i.e., run) them.

The term shell derives its name from the fact that it is an outer layer of an operating system. A shell is an interface between the user and the internal parts of the operating system (at the very core of which is the kernel).

what is lilo?

Lilo means last in last out . LILO is a versatile boot loader for Linux. It does not depend on a specific file system, can boot Linux kernel images from floppy disks and hard disks, and can even boot other operating systems. One of up to sixteen differernt images can be selected at boot time. Various parameters, such as the root device, can be set indepenantly for each kernel. LILO can even be used as the master boot record.

What is Grub?

Grand Unified Bootloader (GRUB)” .A small software utility that loads and manages multiple operating systems (and their variants).

Where Is the Latest Kernel Version on the Internet?

The easiest way to update your kernel is to get the update directly from the distribution which you are running.

If you need or want to configure and compile your own kernel, the web page at http://www.kernel.org/ lists the current versions of the development and production kernels.

What is FSCK?

fsck - check and repair a Linux file system.

fsck is used to check and optionally repair one or more Linux file systems. filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label or UUID specifier (e.g.UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL=root). Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems.

If no filesystems are specified on the command line, and the -A option is not specified, fsck will default to checking filesystems in /etc/fstab serially. This is equivalent to the -As options.

what is partition?

A partition is a section of a hard disk. When you format a hard disk, you can usually choose the number of partitions you want. The computer will recognize each partition as a separate disk, and each will show up under “My Computer” (Windows) or on the desktop (Macintosh).

What is a boot loader?

Most simply, a boot loader loads the operating system. When your machine loads its operating system, the BIOS reads the first 512 bytes of your bootable media (which is known as the master boot record, or MBR). You can store the boot record of only one operating system in a single MBR, so a problem becomes apparent when you require multiple operating systems. Hence the need for more flexible boot loaders.

The master boot record itself holds two things — either some of or all of the boot loader program and the partition table (which holds information regarding how the rest of the media is split up into partitions). When the BIOS loads, it looks for data stored in the first sector of the hard drive, the MBR; using the data stored in the MBR, the BIOS activates the boot loader.

What is PAM?

(Pluggable Authentication Modules) A programming interface that enables third-party security methods to be used in Unix. For example, smart cards, Kerberos and RSA technologies can be integrated with various Unix functions such as rlogin, telnet and ftp.

What is default shell in linux?

Most of the Linux Distributions default shell is bash shell

How to check whether GD enabled in server?

Linux No Comments »

Check GD scrpt.php

<?php
if( !extension_loaded( ‘gd’ ) )
{
echo ‘GD isnt loaded.<br>’;
if( !dl( ‘gd.so’ ) )
echo ‘Couldnt load GD.<br>’;
else
echo ‘Successfully loaded GD.<br>’;
}
else
echo ‘GD is currently loaded.<br>’;
?>

“530 Login authentication failed ” while trying to connect ftp

FTP No Comments »

If “530 Login authentication failed ” while trying to connet ftp .

Then,

1)change to proftpd
2)Synchronize FTP Passwords

3) /scripts/ftpup –force

/scripts/updateuserdomains

/scripts/ftpupdate

Setup Flash Media Server (FMS)

Linux No Comments »

The installation script for Flash Media Server works only on RedHat Enterprise by default. With some modifications it works fine on Ubuntu Edgy:–also in centos :)
apt-get install libnspr4 libstdc++5 libstdc++5-3.3-dev
wget http://download.macromedia.com/pub/flashmediaserver/updates/2_0_3/linux/flashmediaserver2.tar.gz
tar xfz flashmediaserver2.tar.gz
cd FMS*
wget http://www.bluetwanger.de/~mbertheau/fms.patch
patch -p1 < fms.patch
sudo ./installFMS

Email Hosting Transfer Error :Can’t login

Exim No Comments »

After transfer cPanel accounts to another server and all email logins stopped working completely. Everything works fine except email, you get “wrong password” error. You also try to update password via cPanel and still got the same. Deleted all email accounts and re-created them again using old passwords, still can’t login also.

Here the solution…

Login to your server using SSH as root, then run these commands:

# service courier-authlib restart
# service courier-imap restart

What is a Domain?

Linux No Comments »

Domain  Renewal
—————

Every Domain Name registration period ends sooner or later. You have to renew your Domain before its expiration date to make sure you keep your web site up and running in a normal way. Just a friendly reminder, always make sure that you provide the correct personal and contact information to the Registrar. When your Domain Name is about to expire, you will receive at least couple expiry notifications from your Registrar during two months period prior expiration date.

Different stages what the expired Domain Name goes through.
———————————————————–

1)Renewal Grace Period
——————–

The very first period for the Domain Name, right after it expired, is called Renewal Grace Period.During this period the Domain is not active and all services are terminated.The Renewal Grace Period is 40 days for .com, .net, .org, .info, .biz, .us, and .name extensions and there is none such period for Domain Names with extension .cn. You can still renew your Domain during this period at the normal costs. The renewal might take up to 2 business days.

2)Rebdemption Grace Period
————————

The second period is called Redemption Grace Period. It lasts 30 days and it is your last chance to renew your Domain Name. The Domain stays inactive with all services being interrupted. Only your Registrar has the rights to redeem the Domain Name. You can renew it talking directly to the support team of your Registrar and paying Redemption Period Fee which cannot be waived due to Registry Policy. The Domain Name restoration during this period might take up to 3-4 business days.

3)Pending Delete Status
———————

After these two Grace Periods your Domain Name goes into Pending Delete Status for five days. During this period the Domain is marked for deletion by Registry and cannot be renewed. In a five days period Domain is deleted and available for registration by other parties.

Some of the Domain Name’s extensions, such as .de, don’t get any Grace Periods at all and get deleted and available for new public registration right after their expiration date. Domains with .uk extension are held only until 25th day of the month after they expire. But those are few. If you have to clarify you situation you can always contact the domain registrar.

How long is the redemption period?
———————————-

The domain name enters redemption 30-40 days after it has expired.  This redemption period lasts another 30 days, followed by the domain being in a pending delete state for 5 more days. After these 35 days (65-75 days from the date of expiration), the domain is returned to the Internet; however, the domain is almost always purchased by squatters.

Generally, the domain will be immediately purchased by squatters and made available for sale for hundreds and even thousands of dollars. If you want to ensure that you retain ownership of the domain, you must pay the redemption fee to recover the domain.

The cost to retrieve a domain from redemption varies from $100 to $300 and depends on the registrar. The recovery process takes approximately 5 days to complete.

What is the redemption fee?
—————————

The redemption fee is the cost to obtain a domain from redemption. The fee is to cover the costs of the paperwork that the registrar must file to recover the domain. ICANN provided no guidelines on how much the registrar should charge to recover a domain from redemption, so these fees vary from under $100 to over $300.The process of recovering the domain takes approximately 5 days. We must receive the redemption fees before we will start the process of recovering the domain with our registrar.

Can an expired domain be transferred?
————————————-

A domain cannot be transferred once it has expired; not even internally with the same registrar. The domain will need to be renewed first and once it is active again, it can be transferred to our registrar. A domain transfer can take 5 to 7 days to complete. For this reason, we ask that the process be started at least 2 weeks before the domain is due to expire.

Disable Directory Listing

Cpanel No Comments »

Directory listing is enable by default on cPanel, if you’re not put any index file (index.html, index.htm, index.php, etc.) on any folder in any accounts, you will see any files in that folder when browsing.

If you want completely disable directory listing on cpanel, here the tips:

Login to your server using SSH as root, then edit file /etc/httpd/conf/access.conf :

# pico -w /etc/httpd/conf/access.conf

Change the content so look like this:

<Directory />

Options -Indexes FollowSymLinks ExecCGI Includes
AllowOverride All

order allow,deny
allow from all

</Directory>

Basically it’s change from Indexes to -Indexes

Setting Up Cron Job

Linux No Comments »

Setting up cronjobs in Unix and Solaris

cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.
Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.

1. Crontab Restrictions
____________
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.

2. Crontab Commands
__________
export EDITOR=vi ;to specify a editor to open crontab file.

crontab -e     Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

3)3. Crontab file
___________
Crontab syntax :-
A crontab file has five fields for specifying day , date and time  followed by the command to be run at that interval.
*     *   *   *    *  command to be executed
-     -    -    -    -
|     |     |     |     |
|     |     |     |     +—– day of week (0 - 6) (Sunday=0)
|     |     |     +——- month (1 - 12)
|     |     +——— day of month (1 - 31)
|     +———– hour (0 - 23)
+————- min (0 - 59)

* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).

Note: The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .

4. Crontab Example
_______

A line in crontab file like below  removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

30     18     *     *     *         rm /home/someuser/tmp/*

5. Crontab Environment
___________
cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

6. Disable Email
____________

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

>/dev/null 2>&1

7. Generate log file
________________

To collect the cron execution execution log in a file :

30 18  *    *   *    rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

User Cron
———

1)/var/spool/cron

2)tail -f /var/log/cron

eg:

with this command
30 18 * * * rm /home/user/public_html/tmp/*
we can delete all files in tmp folder at 18.30 daily

How do I find out Linux CPU utilization?

Linux No Comments »

Following command will help you to identify CPU utilization, so that you can troubleshoot CPU related performance problems.

Finding CPU utilization is one of the important tasks. Linux comes with various utilities to report CPU utilization. With these commands, you will be able to find out:

* CPU utilization
* Display the utilization of each CPU individually (SMP cpu)
* Find out your system’s average CPU utilization since the last reboot etc
* Determine which process is eating the CPU(s)

Old good top command

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.
The top command monitors CPU utilization, process statistics, and memory utilization. The top section contains information related to overall system status - uptime, load average, process counts, CPU status, and utilization statistics for both memory and swap space.
Top command

Type the top command:

$ top

Find Linux CPU utilization using mpstat and other tools

Please note that you need to install special package called sysstat to take advantage of following commands. This package includes system performance tools for Linux (Red Hat Linux / RHEL includes these tools by default).

# apt-get install sysstat
Use up2date command if you are using RHEL:
# up2date sysstat

Display the utilization of each CPU individually using mpstat

If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. For example, type command:
# mpstat

# mpstat -P ALL
Linux 2.6.9-67.0.1.ELsmp (cochin.armia.com)     02/04/2008

01:10:02 AM  CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
01:10:02 AM  all    4.69    0.00    0.26    0.09    0.02    0.00   94.94   1048.56
01:10:02 AM    0    5.57    0.00    0.24    0.03    0.00    0.00   94.16   1021.09
01:10:02 AM    1    3.82    0.00    0.29    0.14    0.03    0.00   95.72     27.48

The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.:

# mpstat -P ALL

Report CPU utilization using sar command

You can display today’s CPU activity, with sar command:
# sar

# sar
Linux 2.6.9-67.0.1.ELsmp (cochin.armia.com)     02/04/2008

12:00:01 AM       CPU     %user     %nice   %system   %iowait     %idle
12:10:01 AM       all      3.19      0.00      0.19      0.01     96.60
12:20:01 AM       all      8.46      0.00      0.73      0.09     90.73
12:30:01 AM       all      4.48      0.00      0.52      0.16     94.84
12:40:01 AM       all      5.91      0.00      0.66      0.07     93.36
12:50:01 AM       all      5.48      0.00      0.62      0.21     93.69
01:00:01 AM       all      6.35      0.00      0.76      0.03     92.87
01:10:01 AM       all      7.33      0.00      0.78      0.06     91.83
Average:          all      5.89      0.00      0.61      0.09     93.41

Comparison of CPU utilization

The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters. For example display comparison of CPU utilization; 2 seconds apart; 5 times, use:
# sar -u 2 5

Where,

* -u 12 5 : Report CPU utilization. The following values are displayed:
o %user: Percentage of CPU utilization that occurred while executing at the user level (application).
o %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority.
o %system: Percentage of CPU utilization that occurred while executing at the system level (kernel).
o %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
o %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using.
# sar -o output.file 12 8 >/dev/null 2>&1 &

Better use nohup command so that you can logout and check back report later on:
# nohup sar -o output.file 12 8 >/dev/null 2>&1 &

All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed ith the sar command using the -f option.
# sar -f data.file
Task: Find out who is monopolizing or eating the CPUs

Finally, you need to determine which process is monopolizing or eating the CPUs. Following command will displays the top 10 CPU users on the Linux system.
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

OR
# ps -eo pcpu,pid,user,args | sort -r -k1 | less

iostat command

You can also use iostat command which report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. It can be use to find out your system’s average CPU utilization since the last reboot.
# iostat

You may want to use following command, which gives you three outputs every 5 seconds (as previous command gives information since the last reboot):$ iostat -xtc 5 3

GUI tools for your laptops/desktops

Above tools/commands are quite useful on remote server. For local system with X GUI installed you can try out gnome-system-monitor. It allows you to view and control the processes running on your system. You can access detailed memory maps, send signals, and terminate the processes.
$ gnome-system-monitor

—————————–

top
top c

top process causing I/O
———————–
ps auxw|tail +2|sort -k 1.16,1.20nr|head

iostat -d -x
iostat -d -m -x
iostat -x -d 2

cd /sys/devices/system/cpu

Type ls command to see all cpus
ls

Output:
cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7

Inside this directory you will see entry for online or offline CPU

Use “netstat -anp | sort -u” to check for network problems.

atal error: Class ‘jsmfFrontend’ not found in /modules/mod_smf_login.php

Joomla No Comments »

Recently I upgraded one of my clients from Joomla 1.1.1 to 1.1.2.

After installation, I found I was suddenly receiving the following error:-

Fatal error: Class ‘jsmfFrontend’ not found in /modules/mod_smf_login.php on line 107

after installing a patch to upgrade from Joomla 1.1.11 to 1.1.12

I was able to temporarily abolish it by going into my admin and turning off the SMF-Login module (from Modules Menu). It’s obviously an incompatibility between the Joomlahacks SMF bridge login module and the Joomla 1.1.12 upgrade.

The joomla upgrade reinstalls the index.php file in root - so it removes the patch that the joomlahacks smf bridge applies to that file during installation.

You need to go to your admin panel, components, select JoomlaHacks SMF-Bridge, and install, and then ‘click to patch’ the index file..

You might need to chmod your index file to 777 to allow the patch to be applied.

This removes the Fatal error: Class ‘jsmfFrontend’ not found in /modules/mod_smf_login.php on line 107
message

Joomla Admin Password Reset

Joomla No Comments »

If you need to replace  joomla administrator password.

Follow the steps,

Once in the phpMyAdmin select the Joomla’s database from the drop-
down menu at left. The page will refresh and the database’s tables
will be displayed on it. Open the SQL tab (look at the top
navigation bar).

In the text field write the following SQL query:

UPDATE `jos_users` SET `password` = MD5( ‘new_password’ ) WHERE
`jos_users`.`username` = “admin” ;

“new_password” - replace this with the new password you wish to use.
“admin” - replace this if your admin username is different.

Once you are ready, click on the GO button to submit the query. If
everything goes fine without errors, you should be able to login to
Joomla with the new password.

JAuthentication::__construct: Could not load authentication libraries.

Joomla 1 Comment »

To resolve this error, when in phpMyAdmin:

1. Choose the database in question on the left panel / top.
2. Now, when looking at the database displayed, on the left panel, choose _plugins
3. Choose the Structure Tab > Edit the “published” Field (7th item down) and change “0″ to “1″
4. Click “Save”
5. Go to the Browse Tab > id = 1 > name = Authentication-Joomla > Now, click on Edit pencil and change published = “1″ and click on “Go” (save)

http://forum.joomla.org/viewtopic.php?f=432&t=230114

Attachments in mails

Exim No Comments »

If you need to send a file with a particular extension as attachment

To send a file with extension .isp as attachment

Error:-
Not able to send the mail with a file of extension .isp as attachment
Getting Mail Delivery Failure with the following error

“This message has been rejected because it has
potentially executable content $1
This form of attachment has been used by
recent viruses or other malware.
If you meant to send this file then please
package it up as a zip file and resend it.”

Resolution:-

Remove the extension ie .isp from the following files
/etc/antivirus.exim
/etc/cpanel_exim_system_filter

The entries of the file extensions will be given as below in the above files

if $header_content-type: matches “(?:file)?name=(\”[^\"]+\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|scr|sct|shs|url|vb[se]|ws[fhc])\”)”

Managing Mail Queue

Exim No Comments »

If mail queue have more then 10000 mails client is unable to send the mails, you may need to clear out frozen mails.

To list the number of frozen mails
exim -bpru|grep frozen | wc -l

To remove the frozen messages.
exim -bpru|grep frozen|awk {’print $3′}|xargs exim -Mrm

Please check mail queue properly and observer which account is sending the mask mails.
Run following command to delete mails of that account.
Example:grep -lr account@yourdomain.com /var/spool/exim/input/* | xargs rm -rf

Do the following things to delete mail from particular domains.
grep -lr domainname.com /var/spool/exim/input/* |xargs rm -rf


Exim Commands

Exim No Comments »

To print a count of the messages in the queue
root@localhost# exim -bpc

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient)
root@localhost# exim -bp

Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):
root@localhost# exim -bp | exiqsumm

Generate and display Exim stats from a logfile:
root@localhost# eximstats /var/log/exim_mainlog

Same as above, with less verbose output:
root@localhost# eximstats -ne -nr -nt /var/log/exim_mainlog

Same as above, for one particular day:
root@localhost# fgrep YYYY-MM-DD /var/log/exim_mainlog | eximstats

Print what Exim is doing right now:
root@localhost# exiwhat

Searching the queue

Search the queue for messages from a specific sender:
root@localhost# exiqgrep -f [luser]@domain

Search the queue for messages for a specific recipient/domain:
root@localhost# exiqgrep -r [luser]@domain

To Print just the message-id of the entire queue:
root@localhost# exiqgrep -i

Managing the queue

Start a queue run:
root@localhost# exim -q -v

Start a queue run for just local deliveries:
root@localhost# exim -ql -v

Remove a message from the queue:
root@localhost# exim -Mrm <message-id>

Freeze a message:
root@localhost# exim -Mf <message-id>

Deliver a specific message:
root@localhost# exim -M <message-id>

Force a message to fail and bounce:
root@localhost# exim -Mg <message-id>

Remove all frozen messages:
root@localhost# exiqgrep -z -i | xargs exim -Mrm

Freeze all queued mail from a given sender:
root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf

View a message’s headers:
root@localhost# exim -Mvh <message-id>

View a message’s body:
root@localhost# exim -Mvb <message-id>

View a message’s logs:
root@localhost# exim -Mvl <message-id>

Wordpress Themes by Natty WP. Web Hosting
Images by our golf tips desEXign.