Monday, May 16, 2011

visual mode in vi

These commands can be used only after you enable visual mode in vim editor

Shift+V - to enable the visual mode in vim

Then select the lines in the vi

Alt+> - Shift right the selected lines

Alt+< - Shift left the selected lines

c - change the selected lines

y - copy or yank the selected lines to the clipboard.

p - paste the copied lines from the clipboard to the Editor.

getenv in C

getenv in C

this is to get the environmental variable's value in Shell from C file

to store it to a variable use:

fp=getenv("PATH")

The following program will explain it more clearly


This program demonstrates how to get a value for environmental value in shell
and compare it with a predefined variable.

1 #include
2 #include
3 #include
4 int main()
5 {
6 char * cc;
7 cc = getenv("HOME");
8 printf("--->%s<--",cc);
9 if ( strcmp(cc,"/home/karthik") == 0 )
10 {
11 printf("yes the home is /home/karthik");
12 }
13 return 0;
15 }

Editing in vi

Many keywords ease the use of vi

Some of them are:

Ctrl+F - to move forward one page at a time

Ctrl+B - to move backward one page at a time

Ctrl+D - to move half page forward at a time

Ctrl+U - to move half page backward at a time

Ctrl+G - name of the file you are editting

G -last line of the file

1G - move to the first line of the file
--
this any line no you want to move to


H - want the cursor to move to the upper left corner of the screen

M - want to move the cursor to the middle left corner of the screen

L - want to move the cursor to the lower left corner of the screen

Ctrl+R - to Redo the changes in the file

Ctrl+U - to Undo the changes in the file

dw - delete the word

d$ - delete starting from where the cursor is to the end of the line

d0 - delete starting from where the cursor is to the beginning of the line


Editing using numbers:

5cl - delete the 5 characters following the cursor and make it in insert mode

12j - move the cursor down 5 lines

3dw - delete 3 words

substitution in vi:

:g/Local - find the occurence of Local globally and print the instances

:s/Local/Remote - replace the occurence in the current line

:g/Local/s//Remote - for replacing the first occurence

:g/Local/s//Remote/g - for replacing the entire occurence of Local

:g/Local/s//Remote/gp - for replacing and printing the changed occurence

Monday, May 9, 2011

comparators in perl and shell

SHELL:

KSH

you can use == or = to compare string

bash: if you use "==" will lead to syntax errors so be cautious,we have to use only "=" in this case.

Another speciality about = operator is it can be used for both string and numbers.

and can use -eq  for only comparing numbers

And -eq if used for compring strings,it will return syntax error.

PERL

it is just the opposite what you  use in shell

eq can be used to compare only string

= can be used for only numbers

Though = may seem to work for strings it will always return true.So be Cautious.

Saturday, May 7, 2011

Connection refused(public key,password authentication,keyboard interactive)

This error comes when you are trying to login to a machine using ssh or telnet

This may be due to

1)the password you provide may be wrong

2)next chance may be the user account you are using to login to a remote machine can be locked.

for example:ssh karthik@123.45.66.77

this may throw this error
 In this case the karthik account in 123.45.66.77 can be locked.


This can be found out by checking /etc/shadow file in 123.45.66.77 .The karthik account in /etc/shadow file
can be mentioned with *LK* showing it is locked.

extracting .cpio file

syntax:

cat cpio_file | cpio -idmv
use this to extract .cpio file


This works fine.

configuring ssh in Ethernet Switch

Before configuring ssh module in Ethernet switch make sure that ssh modue is installed.

To check ssh module is installed :

show management

this command shows all the module installed in the Ethernet switch  :
if you find the ssh module not installed.Install it before configuring ssh.

After installing  exsshd module,do the following steps:

1)configure ssh2 keys
this is to generate the ssh2 keys

2)enable ssh2
this is to enable the ssh2 module in Ethernet switch.

3)show configuration exsshd 
This will show the configuration of ssh module installed in Ethernet switch.