Thursday, June 13, 2013

Hacking Web applications

Hacking Web applications to fetch the user name and password and secured information .


Step 1: Install the latest version of Mozilla firefox in that any server or client machine.

Step 2: Open your Firefox browser and click the CTRL+SHIFT+A in key board.

Step 3: In right side corner one search box is there like search all add on's click that text box

Step 4: Now enter like Tamper Data its come some add ons. Now install the Tamper data.

Step 5: Then browse your web application and go to Tools menu > Tamper data . Click the Tamper data.

Step 6: Start Tamper and click it.

Step 7: Then Enter your log in user name and password in web application. and click the log in button.

Step 8: It will ask the Tamper. and click the Tamper Button. It will show your login information and also all secured information.

Thursday, August 16, 2012

Dynamically generate the XML file in C#

try {
var pageTracker = _gat._getTracker(“UA-7968286-1″);
pageTracker._trackPageview();
} catch(err) {}
protected void Button1_Click(object sender, EventArgs e)
{
try {
//XmlDataDocument sourceXML = new XmlDataDocument();
string xmlFile = Server.MapPath(“DVDlist.xml”);
//create a XML file is not exist
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(xmlFile, null);
//starts a new document
writer.WriteStartDocument();
//write comments
writer.WriteComment(“Commentss: XmlWriter Test Program”);
writer.Formatting = Formatting.Indented;

writer.WriteStartElement(“DVDlist”);
writer.WriteStartElement(“DVD”);
writer.WriteAttributeString(“ID”, “1″);

//write some simple elements
writer.WriteElementString(“Title”, “Tere Naam”);
writer.WriteStartElement(“Starring”);
writer.WriteElementString(“Actor”, “Salman Khan”);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();

writer.Close();
} catch (Exception e1) { Page.Response.Write(e1); }
}

If any queries in this code pls contact me
Mail Id : sasikumar.ranjith@gmail.com
Contact NO : 9789470655

Wednesday, December 21, 2011

Shell Script While Loop Examples



Can you provide me a while loop control flow statement shell script syntax and example that allows code to be executed repeatedly based on a given boolean condition?

Each while loop consists of a set of commands and a condition. The general syntax as follows for bash while loop:
while [ condition ]
do
 command1
 command2
 commandN
done
  1. The condition is evaluated, and if the condition is true, the command1,2…N is executed.
  2. This repeats until the condition becomes false.
  3. The condition can be integer ($i < 5), file test ( -e /tmp/lock ) or string ( $ans != "" )
ksh while loop syntax:
while [[ condition ]] ; do
 command1
 command1
 commandN
done
 
csh while loop syntax:
while ( condition )
         commands
     end
 

BASH while Loop Example

#!/bin/bash
c=1
while [ $c -le 5 ]
do
 echo "Welcone $c times"
 (( c++ ))
done

KSH while loop Example

#!/bin/ksh
c=1
while [[ $c -le 5 ]]; do
 echo "Welcome $c times"
 (( c++ ))
done

CSH while loop Example

#!/bin/csh
c=1
while ( $c <= 5 )
 echo "Welcome $c times"
 @ c = $c + 1
end
Another example:
#!/bin/csh
set yname="foo"
while ( $yname != "" )
 echo -n "Enter your name : "
 set yname = $<
 if ( $yname != "" ) then
  echo "Hi, $yname"
 endif
end

Monday, November 28, 2011

Add new user in linux

adduser

SYNOPSIS

useradd [options] LOGIN

       useradd -D

       useradd -D [options]

DESCRIPTION

When invoked without the -D option, the useradd command creates a new
       user account using the values specified on the command line and the
       default values from the system. Depending on command line options, the
       useradd command will update system files and may also create the new
       user's home directory and copy initial files. The version provided with
       Red Hat Linux will create a group for each user added to the system by
       default.

OPTIONS

The options which apply to the useradd command are:

       -c, --comment COMMENT
          Any text string. It is generally a short description of the login,
          and is currently used as the field for the user's full name.

       -b, --base-dir BASE_DIR
          The default base directory for the system if -d dir is not
          specified.  BASE_DIR is concatenated with the account name to define
          the home directory. If the -m option is not used, BASE_DIR must
          exist.

       -d, --home HOME_DIR
          The new user will be created using HOME_DIR as the value for the
          user's login directory. The default is to append the LOGIN name to
          BASE_DIR and use that as the login directory name. The directory
          HOME_DIR does not have to exist but will not be created if it is
          missing.

       -e, --expiredate EXPIRE_DATE
          The date on which the user account will be disabled. The date is
          specified in the format YYYY-MM-DD.

       -f, --inactive INACTIVE
          The number of days after a password expires until the account is
          permanently disabled. A value of 0 disables the account as soon as
          the password has expired, and a value of -1 disables the feature.
          The default value is -1.

       -g, --gid GROUP
          The group name or number of the user's initial login group. The
          group name must exist. A group number must refer to an already
          existing group.  /etc/default/useradd.

       -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
          files contained in SKEL_DIR will be copied to the home directory if
          the -k option is used, otherwise the files contained in /etc/skel
          will be used instead. Any directories contained in SKEL_DIR or
          /etc/skel will be created in the user's home directory as well. The
          -k option is only valid in conjunction with the -m option. The
          default is to not create the directory and to not copy any files.

       -l Do not add the user to the last login log file. This is an option
          added by Red Hat.

       -n A group having the same name as the user being added to the system
          will be created by default. This option will turn off this Red Hat
          Linux specific behavior. When this option is used, users by default
          will be placed in whatever group is specified in
          /etc/default/useradd. If no default group is defined, group 1 will
          be used.

       -K, --key KEY=VALUE
          Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK,
          PASS_MAX_DAYS and others).

          Example: -K PASS_MAX_DAYS=-1 can be used when creating system
          account to turn off password ageing, even though system account has
          no password at all. Multiple -K options can be specified, e.g.: -K
          UID_MIN=100
           -K UID_MAX=499

          Note: -K UID_MIN=10,UID_MAX=499 doesn't work yet.

       -o, --non-unique
          Allow the creation of a user account with a duplicate (non-unique)
          UID.

       -p, --password PASSWORD
          The encrypted password, as returned by crypt(3). The default is to
          disable the account.

       -r This flag is used to create a system account. That is, a user with a
          UID lower than the value of UID_MIN defined in /etc/login.defs and
          whose password does not expire. Note that useradd will not create a
          home directory for such an user, regardless of the default setting
          in /etc/login.defs. You have to specify -m option if you want a home
          directory for a system account to be created. This is an option
          added by Red Hat

       -s, --shell SHELL
          The name of the user's login shell. The default is to leave this
          field blank, which causes the system to select the default login
          shell.

       -u, --uid UID
          The numerical value of the user's ID. This value must be unique,

       -b HOME_DIR
          The initial path prefix for a new user's home directory. The user's
          name will be affixed to the end of HOME_DIR to create the new
          directory name if the -d option is not used when creating a new
          account.

       -e EXPIRE_DATE
          The date on which the user account is disabled.

       -f INACTIVE
          The number of days after a password has expired before the account
          will be disabled.

       -g, --gid GROUP
          The group name or ID for a new user's initial group. The named group
          must exist, and a numerical group ID must have an existing entry.

       -s, --shell SHELL
          The name of the new user's login shell. The named program will be
          used for all future new user accounts.

       If no options are specified, useradd displays the current default
       values.

NOTES

The system administrator is responsible for placing the default user
       files in the /etc/skel/ directory.
       This version of useradd was modified by Red Hat to suit Red Hat
       user/group conventions.

CAVEATS

You may not add a user to a NIS group. This must be performed on the
       NIS server.

       Similarly, if the username already exists in an external user database
       such as NIS, useradd will deny the user account creation request.

FILES

/etc/passwd
          User account information.

       /etc/shadow
          Secure user account information.

       /etc/group
          Group account information.

       /etc/gshadow
          Secure group account information.

       /etc/default/useradd

       2  invalid command syntax

       3  invalid argument to option

       4  UID already in use (and no -o)

       6  specified group doesn't exist

       9  username already in use

       10 can't update group file

       12 can't create home directory

       13 can't create mail spool

SEE ALSO

chfn(1), chsh(1), passwd(1), crypt(3), groupadd(8), groupdel(8),
       groupmod(8), login.defs(5), userdel(8), usermod(8).

Thursday, November 24, 2011

Shell scripting Arithmetic operation

Shell Arithmetic

Use to perform arithmetic operations.
Syntax:
expr op1 math-operator op2

Examples:
$ expr 1 + 3
$ expr 2 - 1
$ expr 10 / 2
$ expr 20 % 3
$ expr 10 \* 3
$ echo `expr 6 + 3`

Note:
expr 20 %3 - Remainder read as 20 mod 3 and remainder is 2.
expr 10 \* 3 - Multiplication use \* and not * since its wild card.
For the last statement not the following points
(1) First, before expr keyword we used ` (back quote) sign not the (single quote i.e. ') sign. Back quote is generally found on the key under tilde (~) on PC keyboard OR to the above of TAB key.
(2) Second, expr is also end with ` i.e. back quote.
(3) Here expr 6 + 3 is evaluated to 9, then echo command prints 9 as sum
(4) Here if you use double quote or single quote, it will NOT work
For e.g.
$ echo "expr 6 + 3" # It will print expr 6 + 3
$ echo 'expr 6 + 3' # It will print expr 6 + 3

Rules for Naming variable name (Both UDV and System Variable)

(1) Variable name must begin with Alphanumeric character or underscore character (_), followed by one or more Alphanumeric character. For e.g. Valid shell variable are as follows
HOME
SYSTEM_VERSION
vech
no

(2) Don't put spaces on either side of the equal sign when assigning value to variable. For e.g. In following variable declaration there will be no error
$ no=10
But there will be problem for any of the following variable declaration:
$ no =10
$ no= 10
$ no = 10

(3) Variables are case-sensitive, just like filename in Linux. For e.g.
$ no=10
$ No=11
$ NO=20
$ nO=2

Above all are different variable name, so to print value 20 we have to use $ echo $NO and not any of the following
$ echo $no # will print 10 but not 20
$ echo $No# will print 11 but not 20
$ echo $nO# will print 2 but not 20
(4) You can define NULL variable as follows (NULL variable is variable which has no value at the time of definition) For e.g.
$ vech=
$ vech=""
Try to print it's value by issuing following command
$ echo $vech
Nothing will be shown because variable has no value i.e. NULL variable

Exit Status

By default in Linux if particular command/shell script is executed, it return two type of values which is used to see whether command or shell script executed is successful or not.
(1) If return value is zero (0), command is successful.
(2) If return value is nonzero, command is not successful or some sort of error executing command/shell script.
This value is know as Exit Status.
But how to find out exit status of command or shell script?
Simple, to determine this exit Status you can use $? special variable of shell.
For e.g. (This example assumes that unknow1file doest not exist on your hard drive)
$ rm unknow1file
It will show error as follows
rm: cannot remove `unkowm1file': No such file or directory
and after that if you give command
$ echo $?
it will print nonzero value to indicate error. Now give command
$ ls
$ echo $?

It will print 0 to indicate command is successful.
Exercise
Try the following commands and not down the exit status:
$ expr 1 + 3
$ echo $?

$ echo Welcome
$ echo $?
$ wildwest canwork?
$ echo $?
$ date
$ echo $?
$ echon $?
$ echo $?

Tuesday, November 22, 2011

Linux Shell scripting language

Linux is free. No need to pay the cost and all 
Linux is free.
First ,It's available free of cost (You don't have to pay to use this OS, other OSes like MS-Windows or Commercial version of Unix may cost you money)
Second free means freedom to use Linux, i.e. when you get Linux you will also get source code of Linux, so you can modify OS (Yes OS! Linux OS!!) according to your taste.
It also offers many Free Software applications, programming languages, and development tools etc. Most of the Program/Software/OS are under GNU General Public License (GPL).

Unix Like
Unix is almost 35 year old Os.
In 1964 OS called MULTICS (Multiplexed Information and Computing System) was developed by Bell Labs, MIT & General Electric. But this OS was not the successful one.

Then Ken Thompson (System programmer of Bell Labs) thinks he could do better (In 1991, Linus Torvalds felt he could do better than Minix - History repeats itself.). So Ken Thompson wrote OS on PDP - 7 Computer, assembler and few utilities, this is know as Unix (1969). But this version of Unix is not portable. Then Unix was rewrote in C. Because Unix written in 'C', it is portable. It means Unix can run on verity of Hardware platform (1970-71).
At the same time Unix was started to distribute to Universities. There students and professor started more experiments on Unix. Because of this Unix gain more popularity, also several new features are added to Unix. Then US govt. & military uses Unix for there inter-network (now it is know as INTERNET).
So Unix is Multi-user, Multitasking, Internet-aware Network OS.  Linux almost had same Unix Like feature for e.g.
  • Like Unix, Linux is also written is C.
  • Like Unix, Linux is also the Multi-user/Multitasking/32 or 64 bit Network OS.
  • Like Unix, Linux is rich in Development/Programming environment.
  • Like Unix, Linux runs on different hardware platform; for e.g.
    • Intel x86 processor (Celeron/PII/PIII/PIV/Old-Pentiums/80386/80486)
    • Macintosh PC's 
    • Cyrix processor 
    • AMD processor 
    • Sun Microsystems Sparc processor
    • Alpha Processor (Compaq)

Open Source
Linux is developed under the GNU Public License. This is sometimes referred to as a "copyleft", to distinguish it from a copyright.Under GPL the source code is available to anyone who wants it, and can be freely modified, developed, and so forth. There are only a few restrictions on the use of the code. If you make changes to the programs , you have to make those changes available to everyone. This basically means you can't take the Linux source code, make a few changes, and then sell your modified version without making the source code available. For more details, please visit the open-source home page.

Common vi editor command list
For this PurposeUse this vi Command Syntax
To insert new textesc + i ( You have to press 'escape' key then 'i')
To save fileesc + : + w (Press 'escape' key  then 'colon' and finally 'w')
To save file with file name (save as)esc + : + w  "filename"
To quit the vi editoresc + : + q
To quit without savingesc + : + q!
To save and quit vi editoresc + : + wq
To search for specified word in forward directionesc + /word (Press 'escape' key, type /word-to-find, for e.g. to find word 'shri', type as
/shri)
To continue with search n
To search for specified word in backward directionesc + ?word (Press 'escape' key, type word-to-find)
To copy the line where cursor is locatedesc + yy
To paste the text just deleted or copied at the cursoresc + p
To delete entire line where cursor is locatedesc + dd
To delete word from cursor positionesc + dw
To Find all occurrence of given word and Replace then globally without confirmation esc + :$s/word-to-find/word-to-replace/gFor. e.g. :$s/mumbai/pune/g
Here word "mumbai" is replace with "pune"
To Find all occurrence of given word and Replace then globally with confirmationesc + :$s/word-to-find/word-to-replace/cg
To run shell command like ls, cp or date etc within viesc + :!shell-command

For e.g. :!pwd

How Shell Locates the file
To run script, you need to have in the same directory where you created your script, if you are in different directory your script will not run (because of path settings), For e.g.. Your home directory is ( use $ pwd to see current working directory) /home/vivek. Then you created one script called 'first', after creation of this script you moved to some other directory lets say /home/vivek/Letters/Personal, Now if you try to execute your script it will not run, since script 'first' is in /home/vivek directory, to overcome this problem there are two ways first, specify complete path of your script when ever you want to run it from other directories like giving following command
$ /bin/sh   /home/vivek/first

Now every time you have to give all this detailed as you work in other directory, this take time and you have to remember complete path. 
There is another way, if you notice that all of our programs (in form of executable files) are marked as executable and can be directly executed from prompt from any directory. (To see executables of our normal program give command $ ls -l /bin ) By typing commands like
$ bc
$ cc myprg.c
$ cal
etc, How its possible? All our executables files are installed in directory called /bin and /bin directory is set in your PATH setting, Now when you type name of any command at $ prompt, what shell do is it first look that command in its internal part (called as internal command, which is part of Shell itself, and always available to execute), if found as internal command shell will execute it, If not found It will look for current directory, if found shell will execute command from current directory, if not found, then Shell will Look PATH setting, and try to find our requested commands executable file in all of the directories mentioned in PATH settings, if found it will execute it, otherwise it will give message "bash: xxxx :command not found", Still there is one question remain can I run my shell script same as these executables?, Yes you can, for this purpose create bin directory in your home directory and then copy your tested version of shell script to this bin directory. After this you can run you script as executable file without using command like
$ /bin/sh   /home/vivek/first

Command to create you own bin directory.
$ cd
$ mkdir bin
$ cp first ~/bin
$ first
Each of above commands can be explained as follows:
Each of above commandExplanation
$ cdGo to your home directory
$ mkdir binNow created bin directory, to install your own shell script, so that script can be run as independent program or can be accessed from any directory
$ cp   first ~/bincopy your script 'first' to your bin directory
$ firstTest whether script is running or not (It will run)



Answer to Variable sections exerciseQ.1.How to Define variable x with value 10 and print it on screen.
$ x=10
$ echo $x

Q.2.How to Define variable xn with value Rani and print it on screen
For Ans. Click here
$ xn=Rani
$ echo $xn

Q.3.How to print sum of two numbers, let's say 6 and 3
$ echo 6 + 3
This will print 6 + 3, not the sum 9, To do sum or math operations in shell use expr, syntax is as follows 
Syntax:
expr   op1   operator   op2
Where, op1 and op2 are any Integer Number (Number without decimal point) and operator can be
+ Addition
- Subtraction
/ Division
% Modular, to find remainder For e.g. 20 / 3 = 6 , to find remainder 20 % 3 = 2, (Remember its integer calculation)
\* Multiplication
$ expr 6 + 3
Now It will print sum as 9 , But
$ expr 6+3
will not work because space is required between number and operator (See Shell Arithmetic)

Q.4.How to define two variable x=20, y=5 and then to print division of x and y (i.e. x/y)
For Ans. Click here
$x=20
$ y=5
$ expr x / y


Q.5.Modify above and store division of x and y to variable called z
For Ans. Click here
$ x=20
$ y=5
$ z=`expr x / y`
$ echo $z

Q.6.Point out error if any in following script
$ vi   variscript
#
#
# Script to test MY knolwdge about variables!
#
myname=Vivek
myos   =  TroubleOS    ----->
ERROR 1
myno=5
echo "My name is $myname"
echo "My os is $myos"

echo "My number is   myno,   can you see this number" 
----> ERROR 2
ERROR 1 Read this
ERROR 2 Read this
Following script should work now, after bug fix!
$ vi   variscript
#
#
# Script to test MY knolwdge about variables!
#
myname=Vivek
myos=TroubleOS
myno=5
echo "My name is $myname"
echo "My os is $myos"
echo "My number is   $myno,   can you see this number"

Parameter substitution.
Now consider following command
$($ echo 'expr 6 + 3')
The command ($ echo 'expr 6 + 3')  is know as Parameter substitution. When a command is enclosed in backquotes, the command get executed and we will get output. Mostly this is used in conjunction with other commands. For e.g.
$pwd
$cp /mnt/cdrom/lsoft/samba*.rmp `pwd`
Now suppose we are working in directory called "/home/vivek/soft/artical/linux/lsst" and I want to copy some samba files from "/mnt/cdrom/lsoft" to my current working directory, then my command will be something like
$cp   /mnt/cdrom/lsoft/samba*.rmp    /home/vivek/soft/artical/linux/lsst
Instead of giving above command I can give command as follows
$cp  /mnt/cdrom/lsoft/samba*.rmp  `pwd`
Here file is copied to your working directory. See the last Parameter substitution of `pwd` command, expand it self to /home/vivek/soft/artical/linux/lsst. This will save my time.
$cp  /mnt/cdrom/lsoft/samba*.rmp  `pwd`


Future Point:
What is difference between following two command?
$cp  /mnt/cdrom/lsoft/samba*.rmp  `pwd`

                       
A N D

$cp  /mnt/cdrom/lsoft/samba*.rmp  .


Try to note down output of following Parameter substitution.
$echo "Today date is `date`"
$cal > menuchoice.temp.$$
$dialog --backtitle "Linux Shell Tutorial"  --title "Calender"  --infobox  "`cat  menuchoice.temp.$$`"  9 25 ; read

Answer to if command.
A) There is file called foo, on your disk and you give command, $ ./trmfi   foo what will be output.
Ans.: foo file will be deleted, and message "foo file deleted" on screen will be printed.
B) If bar file not present on your disk and you give command, $ ./trmfi   bar what will be output.
Ans.: Message "rm: cannot remove `bar': No such file or directory" will be printed because bar file does not exist on disk and we have called rm command, so error from rm commad
C) And if you type $ ./trmfi, What will be output.
Ans.:  Following message will be shown by rm command, because rm is called from script without any parameters.
rm: too few arguments
Try `rm --help' for more information.

Answer to Variables in Linux.
1) If you want to print your home directory location then you give command:
     (a) $ echo $HOME
                    or
     (b) $ echo HOME
Which of the above command is correct & why?
Ans.: (a) command is correct, since we have to print the contains of variable (HOME) and not the HOME. You must use $ followed by variable name to print variables cotaines.


Answer to Process Section.
1) Is it example of Multitasking?
Ans.: Yes, since you are running two process simultaneously.
2) How you will you find out the both running process (MP3 Playing & Letter typing)?
Ans.: Try $ ps aux or $ ps ax | grep  process-you-want-to-search
3) "Currently only two Process are running in your Linux/PC environment", Is it True or False?, And how you will verify this?
Ans.: No its not true, when you start Linux Os, various process start in background for different purpose. To verify this simply use top or ps aux command.
4) You don't want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action:
  1. Turn off Speakers
  2. Turn off Computer / Shutdown Linux Os
  3. Kill the MP3 playing process
  4. None of the above
Ans.: Use action no. 3 i.e. kill the MP3 process.
Tip: First find the PID of MP3 playing process by issuing command:
$ ps ax | grep mp3-process-name
Then in the first column you will get PID of process. Kill this PID to end the process as:
$ kill  PID
Or you can try killall command to kill process by name as follows:
$ killall  mp3-process-name


Linux Console (Screen)
How can I write colorful message on Linux Console? , mostly this kind of question is asked by newcomers (Specially those who are learning shell programming!). As you know in Linux everything is considered as a file, our console is one of such special file. You can write special character sequences to console, which control every aspects of the console like Colors on screen, Bold or Blinking text effects, clearing the screen, showing text boxes etc. For this purpose we have to use special code called escape sequence code.  Our Linux console is based on the DEC VT100 serial terminals which support ANSI escape sequence code.
What is special character sequence and how to write it to Console?
By default what ever you send to console it is printed as its. For e.g. consider following echo statement,
$ echo "Hello World"
Hello World
Above echo statement prints sequence of character on screen, but if there is any special escape sequence (control character) in sequence , then first some action is taken according to escape sequence (or control character) and then normal character is printed on console. For e.g. following echo command prints message in Blue color on console
$ echo -e "\033[34m   Hello Colorful  World!"
Hello Colorful  World!

Above echo statement uses ANSI escape sequence (\033[34m), above entire string ( i.e.  "\033[34m   Hello Colorful  World!" ) is process as follows
1) First \033, is escape character, which causes to take some action
2) Here it set screen foreground color to Blue using [34m escape code.
3) Then it prints our normal message Hello Colorful  World! in blue color.
Note that ANSI escape sequence begins with \033 (Octal value) which is represented as ^[ in termcap and terminfo files of terminals and documentation.
You can use echo statement to print message, to use ANSI escape sequence you must use -e option (switch) with echo statement, general syntax is as follows
Syntax
echo   -e  "\033[escape-code    your-message"
In above syntax you have to use\033[ as its with different escape-code for different operations. As soon as console receives the message it start to process/read it, and if it found escape character (\033) it moves to escape mode, then it read "[" character and moves into Command Sequence Introduction (CSI) mode. In CSI mode console reads a series of ASCII-coded decimal numbers (know as parameter) which are separated by semicolon (;) . This numbers are read until console action letter or character is not found (which determines what action to take). In above example
\033Escape character
[Start of CSI
3434 is parameter
mm is letter (specifies action)
Following table show important list of such escape-code/action letter or character
Character or letterUse in CSIExamples
hSet the ANSI modeecho -e "\033[h"
lClears the ANSI modeecho -e "\033[l"
mUseful to show characters in different colors or effects such as BOLD and Blink, see below for parameter taken by m.echo -e  "\033[35m Hello World"
qTurns keyboard num lock, caps lock, scroll lock LED on or off, see below.echo -e "\033[2q"
sStores the current cursor x,y position (col , row position) and attributesecho -e "\033[7s"
uRestores cursor position and attributesecho -e "\033[8u"
m understand following parameters
ParameterMeaningExample
0Sets default color scheme (White foreground and Black background), normal intensity, no blinking etc. 
1Set BOLD intensity$ echo -e "I am \033[1m BOLD \033[0m Person"
I am BOLD Person
Prints BOLD word in bold intensity and next ANSI Sequence remove bold effect (\033[0m)
2Set dim intensity$ echo -e "\033[1m  BOLD \033[2m DIM  \033[0m"
5Blink Effect$ echo -e "\033[5m Flash!  \033[0m"
7Reverse video effect i.e. Black foreground and white background in default color scheme$ echo -e "\033[7m Linux OS! Best OS!! \033[0m"
11Shows special control character as graphics character. For e.g. Before issuing this command press alt key (hold down it) from numeric key pad press 178 and leave both key; nothing will be printed. Now give --> command shown in example and try the above, it works. (Hey you must know extended ASCII Character for this!!!)$ press alt + 178
$ echo -e "\033[11m"
$ press alt + 178
$ echo -e "\033[0m"
$ press alt + 178

25Removes/disables blink effect 
27Removes/disables reverse effect 
30 - 37Set foreground color
31 - RED
32 - Green
xx - Try to find yourself this left as exercise for you :-)
$ echo -e "\033[31m I am in Red"
40 - 47Set background color
xx - Try to find yourself this left as exercise for you :-)
$ echo -e "\033[44m Wow!!!"
q understand following parameters
ParametersMeaning
0Turns off all LEDs on Keyboard
1Scroll lock LED on and others off
2Num lock LED on and others off
3Caps lock LED on and others off
Click here to see example of q command.
Click here to see example of m command.

Click here to see example of s and u command.
This is just quick introduction about Linux Console and what you can do using this Escape sequence. Above table does not contains entire CSI sequences. My up-coming tutorial series on C Programming Language will defiantly have entire story with S-Lang and curses (?). What ever knowledge you gain here will defiantly first step towards the serious programming using c. This much knowledge is sufficient for  Shell Programming, now try the following exercise :-) I am Hungry give me More Programming Exercise & challenges! :-)

1) Write function box(),  that will draw box on screen (In shell Script)
    box (left, top, height, width)
    For e.g. box (20,5,7,40)
  
   
Hint: Use ANSI Escape sequence
1) Use of 11 parameter to m
2) Use following for cursor movement
   row;col H
      or
   rowl;col f
 
  For e.g.
  $ echo   -e "\033[5;10H Hello"
  $ echo   -e "\033[6;10f Hi"

In Above example prints Hello message at row 5 and column 6 and Hi at 6th row and 10th Column.

Monday, November 21, 2011

ipcs Command in LINUX

ipcs Command in LINUX


Purpose

Reports interprocess communication facility status.

Syntax

ipcs [ -m] [ -q] [ -s] [ -S] [ -P] [ -1] [ -a | -b -c -o -p -r -t] [ -T] [ -C CoreFile] [ -N Kernel ] [ -X ] [ -@ [ WparName ] ]

Description

The ipcs command writes to the standard output information about active interprocess communication facilities. If you do not specify any flags, the ipcs command writes information in a short form about currently active message queues, shared memory segments, semaphores, remote queues, and local queue headers.
The column headings and the meaning of the columns in an ipcs command listing follow. The letters in parentheses indicate the flags that cause the corresponding heading to appear. The designator all means the heading is always displayed. These flags only determine what information is provided for each facility. They do not determine which facilities are listed.























































































T (all) the type of facility. There are three facility types:
q
message queue
m
shared memory segment
s
semaphore
ID (all) the identifier for the facility entry.
KEY (all) the key used as a parameter to the msgget subroutine, the semget subroutine, or the shmget subroutine to make the facility entry.
Note: The key of a shared memory segment is changed to IPC_PRIVATE when the segment is removed until all processes attached to the segment detach from it.
MODE (all) the facility access modes and flags. The mode consists of 11 characters that are interpreted as follows:
The first two characters can be the following:
R
If a process is waiting on a msgrcv system call.
S
If a process is waiting on a msgsnd system call.
D
If the associated shared memory segment has been removed. It disappears when the last process attached to the segment detaches it.
C
If the associated shared memory segment is to be cleared when the first attach is run.
-
If the corresponding special flag is not set.
The next nine characters are interpreted as three sets of 3 bits each. The first set refers to the owner's permissions; the next to permissions of others in the user group of the facility entry; and the last to all others. Within each set, the first character indicates permission to read, the second character indicates permission to write or alter the facility entry, and the last character is currently unused.
The permissions are indicated as follows:
r
If read permission is granted.
w
If write permission is granted.
a
If alter permission is granted.
-
If the indicated permission is not granted.
OWNER (all) The login name of the owner of the facility entry.
GROUP (all) The name of the group that owns the facility entry.
CREATOR (a,c) The login name of the creator of the facility entry.
CGROUP (a,c) The group name of the creator of the facility entry.
Note: For the OWNER, GROUP, CREATOR, and CGROUP, the user and group IDs display instead of the login names.
CBYTES (a,o) The number of bytes in messages currently outstanding on the associated message queue.
QNUM (a,o) The number of messages currently outstanding on the associated message queue.
QBYTES (a,b) The maximum number of bytes allowed in messages outstanding on the associated message queue.
LSPID (a,p) The ID of the last process that sent a message to the associated queue. If the last message sent was from a process in a node other than the node that holds the queue, LSPID is the PID of the kernel process that actually placed the message on the queue, not the PID of the sending process.
LRPID (a,p) The ID of the last process that received a message from the associated queue. If the last message received was from a process in a node other than the node that holds the queue, LRPID is the PID of the kernel process that actually received the message on the queue, not the PID of the receiving process.
STIME (a,t) The time when the last message was sent to the associated queue. For remote queues, this is the server time. No attempt is made to compensate for time-zone differences between the local clock and the server clock.
RTIME (a,t) The time when the last message was received from the associated queue. For remote queues, this is the server time. No attempt is made to compensate for any time-zone differences between the local clock and the server clock.
CTIME (a,t) The time when the associated entry was created or changed. For remote queues, this is the server time. No attempt is made to compensate for any time-zone differences between the local clock and the server clock.
NATTCH (a,o) The number of processes attached to the associated shared memory segment.
SEGSZ (a,b) The size of the associated shared memory segment.
CPID (a,p) The process ID of the creator of the shared memory entry.
LPID (a,p) The process ID of the last process to attach or detach the shared memory segment.
ATIME (a,t) The time when the last attach was completed to the associated shared memory segment.
DTIME (a,t) The time the last detach was completed on the associated shared memory segment.
NSEMS (a,b) The number of semaphores in the set associated with the semaphore entry.
OTIME (a,t) The time the last semaphore operation was completed on the set associated with the semaphore entry.
SID (S) The shared memory segment id. SIDs can be used as input to the svmon -S command.

This command supports multibyte character sets.

Flags


-a Uses the -b, -c, -o, -p and -t flags.
-b Writes the maximum number of bytes in messages on queue for message queues, the size of segments for shared memory, and the number of semaphores in each semaphores set.
-c Writes the login name and group name of the user that made the facility.
-CCoreFile Uses the file specified by the CoreFile parameter in place of the /dev/mem file. The CoreFile parameter is a memory image file produced by the Ctrl-(left)Alt-Pad1 key sequence.
-1 When used with the -S flag, writes the list of SIDs unwrapped.
-m Writes information about active shared memory segments.
-NKernel Uses the specified Kernel (the /usr/lib/boot/unix file is the default).
-o Writes the following usage information:
  • Number of messages on queue
  • Total number of bytes in messages in queue for message queues
  • Number of processes attached to shared memory segments
-p Writes process number information:
  • Process number of the last process to receive a message on message queues
  • Process number of last process to send a message on message queues
  • Process number of the creating process
  • Process number of last process to attach or detach on shared memory segments
-P Writes the list of SIDs (segment IDs) associated with the shared memory ID, along with the number of bytes pinned to that segment and an indication of whether the segment is large-page enabled or not. If the segment is large-page enabled, a 'Y' is displayed, otherwise a '-' is displayed.
-q Writes information about active message queues.
-r Writes information about real-time interprocess communication objects.
-s Writes information about active semaphore set.
-S Writes the list of SID attached to shared memory id.
-t Writes time information:
  • Time of the last control operation that changed the access permissions for all facilities
  • Time of the last msgsnd and msgrcv on message queues
  • Time of the last shmat and shmdt on shared memory
  • Time of the last semop on semaphore sets
-T Writes the output of the -t flag with the date.
-X Prints all available characters of each user name, group name of owner, creator, owner group, creator group instead of truncating to the first 8 characters.
-@ [ WparName ] Reports the interprocess-communication facility status for workload partitions. If WparName is specified, the status of the interprocess communication facility is displayed for that particular workload partition. If no WparName is specified, the status of the interprocess communication facility is displayed for all active workload partitions. The name of the workload partition associated with the object is displayed. Specify Global as the WparName to display IPC object information for just that operating system environment, excluding any IPC information for workload partitions hosted from that environment.

Notes:
  1. If the user specifies either the -C or -N flag, the real and effective UID/GID is set to the real UID/GID of the user invoking ipcs.
  2. Values can change while ipcs is running; the information it gives is guaranteed to be accurate only when it was retrieved.

Security

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

Example

Example output from entering ipcs without flags:

IPC status from /dev/mem as of Mon Aug 14 15:03:46 1989
T    ID         KEY        MODE       OWNER     GROUP
Message Queues:
q       0    0x00010381 -Rrw-rw-rw-   root      system
q   65537    0x00010307 -Rrw-rw-rw-   root      system
q   65538    0x00010311 -Rrw-rw-rw-   root      system
q   65539    0x0001032f -Rrw-rw-rw-   root      system
q   65540    0x0001031b -Rrw-rw-rw-   root      system
q   65541    0x00010339--rw-rw-rw-    root      system
q       6    0x0002fe03 -Rrw-rw-rw-   root      system
Shared Memory:
m   65537    0x00000000 DCrw-------   root      system
m  720898    0x00010300 -Crw-rw-rw-   root      system
m   65539    0x00000000 DCrw-------   root      system
Semaphores:
s  131072    0x4d02086a --ra-ra----   root      system
s   65537    0x00000000 --ra-------   root      system
s 1310722    0x000133d0 --ra-------   7003      30720