SlideShare a Scribd company logo
1 of 189
1 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
INDEX Page
1. User Administration 02
2. Networking Advance Concepts : part 1 18
3. Working with Files and Directories 30
4. VI Editor 43
5. Working with Shell 48
6. Process Management 69
7. Drilling Down the File System 90
8. Boot PROM Basics 113
9. Solaris 10 Boot Process & Phases 124
10 .NFS & AutoFS 158
11. SolarisVolume Management
2 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
User Administration
User Administration:
In Solaris each user requires following details:
1. A unique user name
2. A user ID
3. home directory
4. login shell
5. Group to which the user belongs.
System files used for storing user account information are:
The /etc/passwd file:
It contains login information for authorized system user. It
displays following seven fields in each entry:
loginID
A string maximum of 8 chars including numbers &
lowercase and uppercase letters. The first
character should be a letter.
x
It is the password place holder which is stored
under /etc/shadow file.
UID
Unique user ID. System reserves the values 0 to 99
for system accounts. The UID 60001 is reserved for
the nobody account & 60002 is reserved for the
noaccess account. The UID after 60000 should be
avoided.
GID
Group ID. System reserves the values 0 to 99 for
system accounts. The GID numbers for users ranges
from 100 to 60000.
comment Generally contains user full name.
home
directory
Full path for user's home directory.
login
shell
The user's default login shell. It can be anyone
from the list : Bourne shell, Korn shell, C shell,
Z shell, BASH shell, TC shell.
Few default system account entries:
User
name
User
ID
Description
root 0
Root user account which has access to the entire
system
daemon 1
The system daemon account associated with routine
system tasks
bin 2 The Administrative daemon account that is
3 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
associated with routine system tasks
sys 3
The Administrative daemon account that is
associated with system logging or updating files
in temporary directories.
adm 4
The Administrative daemon account that is
associated with system logging
lp 71 Printer daemon account
The /etc/shadow file:
It contains encrypted password.The encrypted password is 13
characters long and encrypted with 128 bit DESA encryption.
The /etc/shadow file contains following fields:
loginID It contains the user's login name
password It contains the 13 letter encrypted password
lastchg
Number of days between 1st January & last password
modification date.
min
Minimum number of days to pass before you can change
the password.
max
Maximum number of days after which a password change
is necessary.
warn
The number of days prior to password expiry that the
user is warned.
inactive
The number of inactive days allowed for the user
before the user account is locked.
expire
The number of days after which the user account would
expire. The number of days are counted since 1st Jan
1970.
flag
It is used to track failed logins. It maintains count
in low order.
The /etc/group file:
It contains default system group entries. This file is used to
create/modify the groups.The /etc/shadow file contains
following fields:
groupname
It contains the name assigned to the group. Maximum
8 characters.
group-
password
It is group password and is generally empty due to
security reasons.
GID Group's GID number.
username-
list
It contains the list of secondary groups with which
user is associated. This list is separated by
4 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
commas and by default maximum of 15 secondary
groups can be associated to each user.
The /etc/default/passwd File:
It is used to control the properties for all user passwords on
the system. The /etc/default/passwd contains following fields:
MAXWEEKS
It is used to set the maximum time
period in weeks for which the password
is valid.
MINWEEKS
It is the minimum time period after
which the password can be changed.
PASSLENGHT
Minimum number of characters for
password length.
WARNWEEKS
It sets the time period prior to
password's expiry that the user should
be warned.
NAMECHECK=NO
Sets the password controls to verify
that the user is not using the login
name as a component of password.
HISTORY=0
Forces the passwd program to store the
number of old passwords. The maximum
number of allowed is 26.
DICTIONLIST=
Causes the passwd program to perform
dictionary word lookups from comma-
separated dictionary files.
DICTIONBDIR=/var/passwd
The location of the dictionary where
the generated dictionary database
reside.
Values in /etc/default/passwd:
Password Management:
pam_unix_auth module is responsible for the password
management in Solaris. To configure locking of user account
after specified number of attempts following parameters are
modified:
5 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
1. LOCK_AFTER_RETRIES tunable parameter in the
/etc/security/policy.conf file &
2. lock_after-retries key in the /etc/user_attr file is
modified.
Note: The LOCK_AFTER_RETRIES parameter is used to specify the
number of failed login attempts after which the user account
is locked. The number of attempts are defined by RETRIES
parameter in the /etc/default/login file.
passwd command:
The passwd command is used to set the password for the user
account.
syntax:
#passwd <options> <user name>
Various options used with the passwd command are described
below:
-s
Shows password attributes for a particular user. When used
with the -a option, attributes for all user accounts are
displayed.
-d
Deletes password for name and unlocks the account. The
login name is not prompted for a password.
-e
Changes the login shell, in the /etc/passwd file, for a
user.
-f
Forces the user to change passwords at the next login by
expiring the password.
-h
Changes the home directory, in the /etc/passwd file, for a
user.
-l
Lock a user's account. Use the -d or -u option to unlock
the account.
-N
Makes the password entry for <name> a value that cannot be
used for login but does not lock the account. It is used
to create password for non-login account(e.g accounts for
running cron jobs).
-u
Unlocks a locked account.
Preventing user from using previously used password:
1. Edit the /etc/default/passwd file and uncomment the line
HISTORY=0
2. Set the value of HISTORY=n, where n is the number of
passwords to be logged and checked.
Managing User Accounts:
Adding a user account:
6 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#useradd -u <User ID> -g <Primary Group> -S <secondary group>
-d <user home dir> -m -c <user Desc> -s <User login shell>
<User Name>
The option -m forcibly creates the user home directory if it
is not there.
Note: The default group id will be 1(group name is system).
useradd command options:
-c
<comment>
A short description of the login, typically the
user's name and phone extension. This string can
be up to 256 characters.
-d
<directory>
Specifies the home directory of the new user. This
string is limited to 1,024 characters.
-g <group> Specifies the user's primary group membership.
-G <group> Specifies the user's secondary group membership.
-n <login> Specifies the user's login name.
-s <shell> Specifies the user's login shell.
-u <uid>
Specifies the user ID of the user you want to add.
If you do not specify this option, the system
assigns the next available unique UID greater than
100.
-m
SeCreates a new home directory if one does not
already exist.
Default values for creating a user account:
There is a preset range of default values associated with the
useradd command. These values can be displayed using -D
option. The useradd command with -D option creates a file
/use/sadm/defadduser for the first time. The values in
/use/sadm/defadduser is used as default values for useradd
command.
Example: Adding a new user account test.
7 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Note: When a user account is created using useradd command it
is locked and need to be unlocked & password is set using
passwd command.
Modifying a user account:
Modifying a user id: # usermod -u <New User ID> <User Name>
Modifying a primary group: #usermod -g <New Primary Group>
<User Name>
Modifying a secondary group: #usermod -G <New Secondary Group>
<User Name>
In similar manner we can modify other user related
information.
Deleting a user account:
#userdel <user name> → user's home directory is not deleted
#userdel -r <user name> → user's home directory is deleted
Locking a User Account:
# passwd -l <user name>
Unlock a User Account:
#passwd -u <user name>
Note: uid=0 (Super user, administrator having all privileges).
By default root is having uid = 0 which can be duplicated.
This is the only user id which can be duplicated.
8 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
For example:
1. #useradd -u 0 -o <user name>
2. #usermod -u 0 -o <user name>
Here option -o is used to duplicate the user id 0.
smuser command:
This command is used for remote management of user accounts.
Example: If you want to add a user raviranjan in nis domain
office.com on system MainPC use smuser command as follows:
# /usr/sadm/bin/ smuser add -D nis:/MainPC/office.com -- -u 111
-n raviranjan
The subcommands used with smuser command:
add To add a new user account.
modify To modify a user account.
delete To delete a user account.
list To list one or more user accounts.
smuser add options:
-c <comment>
A short description of the login, typically the
user's name and phone extension. This string can
be up to 256 characters.
-d
<directory>
Specifies the home directory of the new user.
This string is limited to 1,024 characters.
-g <group> Specifies the user's primary group membership.
-G <group> Specifies the user's secondary group membership.
-n <login> Specifies the user's login name.
-s <shell> Specifies the user's login shell.
-u <uid>
Specifies the user ID of the user you want to
add. If you do not specify this option, the
system assigns the next available unique UID
greater than 100.
-x
autohome=Y|N
Sets the home directory to automount if set to Y.
smgroup command:
This command is used for remote management of groups.
Example: If you want to add a group admin in nis domain
office.com on system MainPC use smgroup command as follows:
#/usr/sadm/bin/smgroup add -D nis:/MainPC/office.com -- -g 101
-n admin
The subcommands used with smgroup command:
add To add a new group.
9 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
modify To modify a group.
delete To delete a group.
list To list one or more group.
Note: The use of subcommands requires authorization with the
Solaris Management Console server. Solaris Management Console
also need to be initialized.
Managing Groups:
There are two groups related to a user account:
1. Primary Group: The maximum and minimum number of primary
group for a user is 1.
2. Secondary Group: A user can be member of maximum 15
secondary groups.
Adding a group
#groupadd <groupname>
#groupadd -g <groupid> <groupname>
The group id is updated under /etc/group.
#vi /etc/group
ss2::645
Note: Here ss2 is group name and 645 is group id.
Modifying a group
By group ID: #groupmod -g <New Group ID> <Old Group Name>
By group Name: #groupmod -n <New Group Name> <Old Group Name>
Note:
For every group we are having a group name and id(for kernel
reference). By default 0-99 group ids are system defined.
The complete information about the group is stored under
/etc/group file.
Deleting a group
# groupdel <group name>
Variables for customizing a user session:
Variable
Set
By
Description
LOGNAME login Defines the user login name
HOME login
used to set path of user's home directory and
is the default argument of the cd command
SHELL login Contains path to the default shell
10 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
PATH login
Sets the default path where the command is
searched
MAIL login Sets path to the mailbox of the user
TERM login Used to define the terminal
PWD shell Defines the current working directory
PS1 shell Defines shell prompt for bourne or korn shell
prompt shell Contains the shell prompt for C shell
Setting login variables for the shell:
Shell User's Initialization file
Bourne/Korn
VARIABLE=value;export VARIBLE
eg:#PS1="$HOSTNAME";export PS1
C setenv variable value
Monitoring System Access:
who command :
This command displays the list of users currently logged in to
the system.
It contains user's login name, device(eg. console or
terminal), login date & time and the remote host IP address.
ruser command:
This command displays the list of users logged in to the local
and remote host. The output is similar to the who command.
Finger Command:
By default, the finger command displays in multi-column format
the following information about each logged-in user:
user name
user's full name
terminal name(prepended with a '*' (asterisk) if write-
permission is denied)
idle time
login time
host name, if logged in remotely
Syntax:
finger [ -bfhilmpqsw ] [ username... ]
finger [-l ] [
username@hostname1[@hostname2...@hostnamen] ... ]
finger [-l ] [ @hostname1[@hostname2...@hostnamen] ... ]
Options:
-b Suppress printing the user's home directory and shell
in a long format printout.
11 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
-f Suppress printing the header that is normally printed
in a non-long format printout.
-h Suppress printing of the .project file in a long format
printout.
-i Force "idle" output format,which is similarto short
format except that only the login name,terminal,login time,and
idle time are printed.
-l Force long output format.
-m Match arguments only on user name (not first or last
name).
-p Suppress printing of the .plan file in a long format
printout.
-q Force quick output format, which is similar to short
format except that only the login name, terminal, and login
time are printed.
-s Force short output format.
-w Suppress printing the full name in a short format
printout.
Note: The username@hostname form supports only the -l option.
last command:
The output of this command is very long and contains
information about all the users. We can user the last command
in following ways:
1. To display the n lines from the o/p of last command:
#last -n 10
2. Login information specific to a user:
#last <user name>
3. last n reboot activities:
#last -10 reboot
12 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Recording failed login attempts:
1. Create a file /var/adm/loginlog.
#touch /var/adm/loginlog
2. Root user should be the owner of this file and it should
belog to group sys.
#chown root:sys /var/adm/loginlog
3. Assign read and write permission for the root user.
#chmod 600 /var/adm/loginlog
This will log all failed login attempts after five consecutive
failed attempts. This can be changed by modifying the RETRIES
entry in /etc/default/login.
The loginlog file contains:
user's login name
user's login device
time of the failed attempt
su command:
The su (substitute user) command enables to change a login
session's owner without the owner having to first log out of
that session.
Syntax:
#su [options] [commands] [-] [username]
Examples:
#su
The operating system assumes that, in the absence of a
username, the user wants to change to a root session, and thus
the user is prompted for the root password as soon as the
13 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
ENTER key is pressed. This produces the same result as typing:
#su root
To transfer the ownership of a session to any other user, the
name of that user is typed after su and a space.
#su ravi
The user will then be prompted for the password of the account
with the username ravi.
The '-' option with su command:
1. Executes the shell initialization files of the switched
user.
2. Modifies the work environment to change it to the work
environment of the specified user.
3. Changes the user's home directory.
The whoami command:
This command displays the name of the currently logged in
user.
Example:
#su ravi
$whoami
ravi
$
The 'who am i' command:
This displays the login name of the original user.
Example:
#whoami
root
#su ravi
$who am i
root
$
Monitoring su attempts:
You can monitor su attempts by monitoring the /var/adm/sulog
file. This file logs each time the su command is used. The su
logging in this file is enabled by default through the
following entry in the /etc/default/su file:
SULOG=/var/adm/sulog
The sulog file lists all uses of the su command, not only the
su attempts that are used to switch from user to superuser.
The entries show the date and time the command was entered,
whether or not the attempt was successful (+ or -), the port
from which the command was issued, and finally, the name of
the user and the switched identity.
14 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
The console parameter in /etc/default/su file contains the
device name to which all atempts to switch user should be
logged
CONSOLE=/dev/console
By default this option is commented.
Controlling system Access:
1. /etc/default/login: CONSOLE Variable: This parameter can be
used to restrict the root user login. The value /dev/console
for CONSOLE variable enables the root user to login from
system console only. The remote login for root is user is not
possible. However, if the parameter CONSOLE is commented or
not defined, the root user can login to the device from any
other system on the networ.
PASSREQ: If set to YES, forces user to enter the password when
they login for first time. This is applicable for the user
account with no password.
2. /etc/default/passwd:
It is centralized password aging file for all this normal
users. If we update any information to this file,
automatically all users will be updated.
3. /etc/nologin:
It is the file which is responsible for restricting all the
normal users not to access server. By default this file does
not exists.
To restrict all normal users from login:
#touch /etc/nologin
#vi /etc/nologin
Server is under maintenance. Please try after 6:00PM.
:wq!
4./etc/skel: It is the directory which contains all the users
environmental files information. When we are creating the user
with useradd command along with -m attributes it starts
copying all the environmental files from /etc/skel to user’s
home directory.
5. /etc/security/policy.conf
To lock the user after repeated failed logins#vi
/etc/security/policy.conf
(go to last line)
LOCK_FAILED_LOGINS = NO (Change it to YES)
6. /var/adm/lastlog
7. /var/adm/wtmp
15 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
8. /etc/ntmp
Note: The following file systems are the binary files
responsible for recording last users login & log out
information:
1. /var/adm/lastlog
2. /var/adm/wtmp
3. /etc/ntmp
9. /etc/ftpd/ftpuser:
This contains the list of user not allowed to access the
system using the ftp protocol.
chown command:Use the chown command to change file ownership.
Only the owner of the file or superuser can change the
ownership of a file.
Syntax:
#chown -option <user name>|<user ID> <file name>
You can change ownership on groups of files or on all of the
files in a directory by using metacharacters such as * and ?
in place of file names or in combination with them.
You can change ownership recursively by use the chown -R
option. When you use the -R option, the chown command descends
through the directory and any sub directories setting the
ownership ID. If a symbolic link is encountered, the ownership
is changed only on the target file itself.
chgrp command:
This command is used to change the ownership of the group
owner of the file or directory.
Syntax:
#chgrp <group name>|<group ID> <file names>
setuid Permission:
When setuid (set-user identification) permission is set on an
executable file, a process that runs this file is granted
access based on the owner of the file (usually root), rather
than the user who created the process. This permission enables
a user to access files and directories that are normally
available only to the owner.
The setuid permission is shown as an s in the file
permissions. For example, the setuid permission on the passwd
command enables a user to change passwords, assuming the
permissions of the root ID are the following:
# ls -l /usr/bin/passwd
-r-sr-sr-x 3 root sys 96796 Jul 15 21:23
/usr/bin/passwd
16 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
NOTE: Using setuid permissions with the reserved UIDs (0-99)
from a program may not set the effective UID correctly.
Instead, use a shell script to avoid using the reserved UIDs
with setuid permissions.
You setuid permissions by using the chmod command to assign
the octal value 4 as the first number in a series of four
octal values. Use the following steps to setuid permissions:
1. If you are not the owner of the file or directory,
become superuser.
2. Type chmod <4nnn> <filename> and press Return.
3. Type ls -l <filename> and press Return to verify that
the permissions of the file have changed.
The following example sets setuid permission on the myprog
file:
#chmod 4555 myfile
-r-sr-xr-x 1 ravi admin 12796 Jul 15 21:23 myfile
#
setgid Permission
The setgid (set-group identification) permission is similar to
setuid, except that the effective group ID for the process is
changed to the group owner of the file and a user is granted
access based on permissions granted to that group. The
/usr/bin/mail program has setgid permissions:
# ls -l /usr/bin/mail
-r-x—s—x 1 bin mail 64376 Jul 15 21:27
/usr/bin/mail
#
When setgid permission is applied to a directory, files
subsequently created in the directory belong to the group the
directory belongs to, not to the group the creating process
belongs to. Any user who has write permission in the directory
can create a file there; however, the file does not belong to
the group of the user, but instead belongs to the group of the
directory.
You can set setgid permissions by using the chmod command to
assign the octal value 2 as the first number in a series of
four octal values. Use the following steps to set setgid
permissions:
1. If you are not the owner of the file or directory,
become superuser.
17 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
2. Type chmod <2nnn> <filename> and press Return.
3. Type ls -l <filename> and press Return to verify that
the permissions of the file have changed.
The following example sets setuid permission on the myfile:
#chmod 2551 myfile
#ls -l myfile
-r-xr-s—x 1 ravi admin 26876 Jul 15 21:23 myfile
#
Sticky Bit
The sticky bit on a directory is a permission bit that
protects files within that directory. If the directory has the
sticky bit set, only the owner of the file, the owner of the
directory, or root can delete the file. The sticky bit
prevents a user from deleting other users' files from public
directories, such as uucppublic:
# ls -l /var/spool/uucppublic
drwxrwxrwt 2 uucp uucp 512 Sep 10 18:06
uucppublic
When you set up a public directory on a TMPFS temporary file
system, make sure that you set the sticky bit manually.
You can set sticky bit permissions by using the chmod command
to assign the octal value 1 as the first number in a series of
four octal values. Use the following steps to set the sticky
bit on a directory:
1. If you are not the owner of the file or directory,
become superuser.
2. Type chmod <1nnn> <filename> and press Return.
3. Type ls -l <filename> and press Return to verify that
the permissions of the file have changed.
The following example sets the sticky bit permission on the
pubdir directory:
# chmod 1777 pubdir
# ls -l pubdir
drwxrwxrwt 2 winsor staff 512 Jul 15 21:23 pubdir
18 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Viewing & monitoring Network Interfaces:
Following are the three important commands used for viewing &
monitoring network interfaces:
1. ifconfig:
This command shows OSI layer 2 related information. To display
all the status of all interfaces use following command:
# ifconfig -a
lo0:
flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
The above command shows that the interface lo0 is up with IP
address 127.0.0.1
ifconfig can be used to up or down the interface:
#ifconfig lo0 down
#ifconfig lo0 up
2. ping:
This command is used to communicate with another system over
the network. The ping uses ICMP protocol to communicate.
#ping computer1
computer1 is alive
#ping computer2
no answer
In the above example the computer1 is reachable but computer2
is not reachable.
3. snoop:
It is used to capture and inspect network packets to determine
the kind of data transferred between systems.
#snoop system1 system2
system1 -> system2 ICMP Echo request (ID:710 Sequence
number:0)
system2 -> system1 ICMP Echo reply (ID:710 Sequence number:0)
The above command is used to intercept the communication
between system1 & system2. The system1 is trying to ping
system2 and the ping is success.
snoop -o <file name>: Saves captured packets in file name as
they are captured
snoop -i <file name>: Displays packets previously captured in
19 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
file name
snoop -d <device>: Receives packets from a network interface
specified by device
The Network Interfaces in Solaris is controlled by files &
services:
svcs:/network/physical:default Service
This service calls /lib/svcs/method/net-physical method
script. This script is run every time the system is rebooted.
This script uses ifconfig utility to configure each interface.
It searches for file /etc/hostname.xxn. For each
/etc/hostname.xxn file, the script uses ifconfig command with
the plumb option to make kernel ready to communicate to the
interface. The script then configures the names interfaces by
using other options of the ifconfig command.
Note: In Solaris 8 & 9, the /etc/rcS.d/S30network.sh file is
used to perform the same function. Before Solaris 8 OS, the
/etc/rcS.d/S30rootusr.sh fiel was used.
/etc/hostname.xxn files
These file contains an entry that configures a corresponding
interface. The variable component (xx) is replaced by an
interface type and a number that differentiates between
multiple interface of the same type configured in the
system.The following table shows an example of file entries
for Ethernet interfaces commonly found in Solaris systems:
/etc/hostname.e1000g0
First e1000g (Intel PRO/1000 Gigabit
family device driver) Ethernet interface
in the system
/etc/hostname.bge0
First bge (Broadcom Gigabit Ethernet
device driver) Ethernet interface in the
system
/etc/hostname.bge1
Second bge Ethernet interface in the
system
/etc/hostname.ce0
First ce (Cassini Gigabit Ethernet Device
driver) Ethernet interface in the system
/etc/hostname.qfe0
First qfe(Quad Fast-Ethernet Device
driver) Ethernet interface in the system
/etc/hostname.hme0
First hme (Fast-Ethernet Device driver)
Ethernet interface in the system
/etc/hostname.eri0
First eri (eri Fast-Ethernet Device
driver) Ethernet interface in the system
/etc/hostname.nge0
First nge (Nvidia Gigabit Ethernet Device
driver) Ethernet interface in the system
20 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
The /etc/hostname.xxn files contain either the host name or
the IP address of the system that contains the xxn interface.
The host name must be there in the file /etc/inet/hosts file
so that it can be resolved to an IP address at system boot.
Example:
# cat /etc/hostname.ce0
Computer1 netmask + broadcast + up
/etc/inet/hosts file:
It is the file which associates the IP addresses of hosts with
their names.It can be used with, or instead of , other hosts
databases including DNS, NIS hosts map & NIS+ hosts table.
The /etc/inet/hosts file contains at least the loopback & host
information. It has one entry for each IP address of each
host. The entries in the files are in following format:
<IP address> <Host name> [aliases]
127.0.0.1 localhost
/etc/inet/ipnodes file:
It is a local database or file that associates the names of
nodes with their IP addresses. It is a symbolic link to the
/etc/inet/hosts file. It associates the names of nodes with
their Internet Protocol (IP) addresses. The ipnodes file can
be used in conjuction with, instead of, other ipnodes
databases, including the DNS, the NIS ipnodes map, and LDAP.
The fomat of each line is:
<IP address> <Host Name> [alias]
# internet host table
::1 localhost
127:0:0:1 localhost
10.21.108.254 system1
Changing the System Host Name:
The system host name is in four system files & we must modify
these files and perform a reboot to change a system host name:
/etc/nodename
/etc/hostname.xxn
/etc/inet/hosts
/etc/inet/ipnodes
sys-unconfig Command:
The /usr/sbin/sys-unconfig command is used to restore a system
configuration to an unconfigured state. This command does the
following:
1. It saves the current /etc/inet/hosts files information in
the /etc/inet/hosts.saved file.
2. It saves the /etc/vfstab files to the /etc/vfstab.orig file
if the current /etc/vfstab file contains NFS mount entries.
3. It restores the default /etc/inet/hosts file.
21 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
NETSTAT:
It lists the connection for all protocols and address family
to and from machine.
The address family (AF) includes:
INET – ipv4
INET - ipv6
UNIX – Unix Domain Sockets(Solaris/FreeBSD/Linux etc.)
Protocols supported in INET/INET6 are:
TCP, IP, ICMP(PING), IGMP, RAWIP, UDP(DHCP, TFTP)
NETSTAT also list:
1. routing tables,
2. any multi-cast entry for NIC,
3 .DHCP status for various interfaces,
4.net-to-media/MAC table.
Usage:
# netstat
UDP: Ipv4
Local Address Remote Address State
-------------------- -------------------- ----------
System1.bge0.54844 10.95.8.202.domain Connected
System1.bge0.54845 10.95.8.213.domain Connected
TCP: Ipv4
Local Address Remote Address Swind Send-Q Rwind Recv-Q State
-------------------- -------------------- ----- ------ ----- -
----- -----------
localhost.41771 localhost.3306 49152 0 49152 0 ESTABLISHED
localhost.3306 localhost.41771 49152 0 49152 0 ESTABLISHED
localhost.50230 localhost.3306 49152 0 49152 0 CLOSE_WAIT
localhost.50231 localhost.3306 49152 0 49152 0 CLOSE_WAIT
Note: NETSTAT returns sockets by protocol using /etc/services
lookup. Below example gives detailed information about the
/etc/services files.
# ls -ltr /etc/services
lrwxrwxrwx 1 root root 15 Apr 8 2009 /etc/services ->
./inet/services(its soft link to /etc/inet/services)
The below example shows the content of the /etc/services file.
Its columns represents Network services, port number and
Protocol.
# less /etc/services
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
22 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#ident "@(#)services 1.34 08/11/19 SMI"
#
# Network services, Internet style
#
tcpmux 1/tcp
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
daytime 13/tcp
daytime 13/udp
netstat 15/tcp
Note: The NETSTAT command resolves the host name with the help
of local /etc/hosts file or DNS server. There is an important
file /etc/resolv.conf which tells resolver what look up
facilities such as LDAP, DNS or files to use.
/etc/nssswitch.conf is consulted by netstat to resolve names
for IP.
/etc/resolv.conf:
# cat /etc/resolv.conf
domain WorkDomain
nameserver 10.95.8.202
nameserver 10.95.8.213
/etc/hosts file:
# cat /etc/hosts
127.0.0.1 localhost
172.30.228.58 mysystem.bge0 bge0
172.30.228.58 mysystem loghost
The command netstat -a will dump the connection including name
lookup from /etc/services directly. It returns all protocols
for all address families (TCP/UDP/UNIX).
#netstat -a
UDP: Ipv4
Local Address Remote Address State
-------------------- -------------------- ----------
*.snmpd Idle
*.55466 Idle
System1.bge0.55381 10.95.8.202.domain Connected
System1-prod.bge0.55382 10.95.8.213.domain Connected
*.32859 Idle
#netstat -an :
-n option disables the name resolution of hosts and ports and
speed up the o/p time
23 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#netstat -i:
returns state of configured interfaces.
# netstat -i
Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue
lo0 8232 loopback localhost 1498672734 0 1498672734 0 0 0
nge0 1500 System1.bge0 System1.bge0 1081897064 0 1114394170 6
0 0
#netstat -m :
It returns streams(TCP) statistics
streams allocation:
cumulative allocation
current maximum total failures
streams 408 4350 28881897 0
queues 841 4764 43912097 0
mblk 7062 40068 780613980 0
dblk 7062 45999 4815973363 0
linkblk 5 84 6 0
syncq 17 75 58511 0
qband 0 0 0 0
2469 Kbytes allocated for streams data
#netstat -p :
It returns net to media information(MAC/layer-2 information).
Net to Media Table: Ipv4
Device IP Address Mask Flags Phys Addr
------ -------------------- --------------- -------- ---------
------
nge0 defaultrouter 255.255.255.255 00:50:5a:1e:e4:01
nge0 172.30.228.54 255.255.255.255 00:14:4f:6f:39:13
nge0 172.30.228.52 255.255.255.255 o 00:14:4f:7e:97:53
nge0 172.30.228.53 255.255.255.255 o 00:14:4f:6f:4f:75
nge0 172.30.228.49 255.255.255.255 00:1e:68:86:84:16
nge0 System1.bge0 255.255.255.255 SPLA 00:21:28:70:19:36
nge0 System2 255.255.255.255 o 00:21:28:6b:c6:7a
nge0 172.30.228.57 255.255.255.255 SPLA 00:21:28:70:19:36
nge0 224.0.0.0 240.0.0.0 SM 01:00:5e:00:00:00
#netstat -P <protocol>
(ip|ipv6|icmp|icmpv6|tcp|udp|rawip|raw|igmp): returns active
sockets for selected protocol.
#netstat -r : returns routing table
# netstat -r
Routing Table: Ipv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- --------
-- ---------
default defaultrouter UG 1 53637
172.30.228.0 System1.bge0 U 1 3295 nge0
172.30.228.0 172.30.228.57 U 1 0 nge0:1
224.0.0.0 System1.bge0 U 1 0 nge0
24 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
localhost localhost UH 201 15889818 lo0
#netstat -D :
It returns DHCP Configuration information (lease
duration/renewal etc.)
#netstat -a -f <address_family>:
It returns result corresponding to the specified address
family
netstat -a -f inet|inet6|unix
netstat -a -f inet : It returns ipv4 information only.
Network Configuration
There are two main configuration:
1. Local files : configuration is defined statically via key
files
2. Network configuration : DHCP is used to auto-config
interfaces
dladm command: It is used to determine the physical interfaces
using following command:
dladm show-dev or show-link.
The another command to check the same is ifconfig -a. However
there is a difference between O/Ps.
The dladm shows layer 1 related information whereas ifconfig
command returns layer 2&3 related information.
# dladm show-dev
ce0 link: unknown speed: 1000 Mbps
duplex: full
ce1 link: unknown speed: 1000 Mbps
duplex: full
ge0 link: unknown speed: 1000 Mbps
duplex: unknown
eri0 link: unknown speed: 100 Mbps
duplex: full
# ifconfig -a
lo0:
flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
ce0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu
1500 index 6
inet 10.22.213.80 netmask ffffff00 broadcast
10.22.213.255
ether 0:14:4f:67:90:c1
ce1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu
25 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
1500 index 3
inet 10.22.217.35 netmask ffffff00 broadcast
10.22.217.255
ether 0:14:4f:44:4:50
eri0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu
1500 index 4
inet 10.22.224.147 netmask ffffff00 broadcast
10.22.224.255
ether 0:14:4f:47:92:5e
ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu
1500 index 5
inet 10.22.240.108 netmask ffffff00 broadcast
10.22.240.255
ether 0:14:4f:47:92:5f
Key network configuration files:svcs -a | grep physical : This
command can be used to see the service responsible for
running/starting the physical interfaces.
svcs -a | grep loopback: This command can be used to see the
service responsible for running/starting the local loopback
interface.
Configuring Network
1. IP Address( /etc/hostname.interface): We need to configure
/etc/hostname.interface(e.g /etc/hostname.e1000g0,
/etc/hostname.iprb01) for each physical and virtual interface
listed by the dladm command. The IP address must be listed in
this file. However this is not a requirement in DHCP or
network configuration mode.
2. Domain name( /etc/defaultdomain): We need to configure
/etc/defaultdomain. This is not a requirement in case of DHCP
mode of network configuration. This contains domain name
information for the host.
3.Netmask(/etc/inet/netmasks): We need to create a files
/etc/inet/netmasks if not there. This is also managed by DHCP.
The netmasks file associates Internet Protocol (IP) address
masks with IP network numbers.
network-number netmask
The term network-number refers to a number obtained from the
Internet Network Information Center. Both the network-number
and the netmasks are specified in "decimal dot" notation, e.g:
128.32.0.0 255.255.255.0
4. Hosts database(/etc/hosts): It is symbolically linked with
/etc/inet/hosts, contains the entry for the loopback adapter
and for each IP address linked with the network adapter for
name resolution. It gets auto configured by DHCP.
26 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
5. Client DNS resolver file(/etc/resolv.conf): It reveals dns
resolver related information. It gets auto configured by DHCP.
6. Default gateway(/etc/defaultrouter): It is required for
communicating with outside network. It is also managed by DHCP
under network configuration mode.
7. Node name(/etc/nodename): This file contains the host name
and is not mandatory as the host name is resolved by the
/etc/hosts file. This is taken care by DHCP in network
configuration.
Name service configuration file(/etc/nsswitch.conf): It will
reveal resolution of various objects.
For manually configuring the network from DCP to local
files(static) mode, the above mentioned files need to be
configured as stated. Once that is done, move/rename/delete
the file dhcp.<interfacename>, so that the DHCP agent is not
invoked.
Plumb/enable the iprb0 100mbps interface(Plumbing interfaces
is analogous to enable interfaces):
1. ifconfig iprb0 plumb up → This will enable iprb0 interface.
2. ifconfig iprb0 172.16.20.10 netmask 255.255.255.0 → This
will enable layer 3 Ipv4 address.
3. Ensure that the newly plumbed persists across reboot:
1. Creating a file /etc/hostname.interface: echo
“172.16.20.10” > /etc/hostname.<interfacename>
2. Create an entry in /etc/hosts file:
echo “172.16.20.10 NewHostName” >> /etc/hosts
3. Create an entry in file /etc/inet/netmasks
echo “172.16.20.0 255.255.255.0” >> /etc/inet/netmasks
Unplumb(disable) an interface: ifconfig <interface name>
unplumb down
Making an interface to go down without unplumb : ifconfig
<interfacename> down
Removing an interface: ifconfig <interfacename> removeif <IP
Address of interface>
Note: If you want the interface to be managed DHCP, create a
file dhcp.<interfacename> under /etc directory.
Logical(Sub-interfaces) Network Interfaces:For each physical
interface many logical interfaces can be created connected to
a switch port. This means adding additional IP address to a
physical interface.
1. Use ‘ifconfig <interfacename> addif <ip address> <net
27 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
mask>’:
ifconfig e100g0 addif 192.168.1.51 (RFC-1918 – defaults /24)
This will automatically create e100g0:1 logical interface.
2.Making the interface to go up: ifconfig e100g0:1 up
Note:
1. This will automatically create an e100g0:1 logical
interface.
2. Solaris places new logical interface in down mode by
default.
3. Logical/sub-interface are contingent upon physical
interface. It means if the physical interface is down the
logical interface will also be down.
4. Connections are sourced using the IP address of the
physical interface.
Save logical/sub-interface for persistent across reboots:
1. Create file /etc/hostname.<interfacename> and make
interface IP address as entry to it.
2. Optionally update/etc/hosts file.
3. Optionally update /etc/inet/netmasks file – when
subnetting.
NSSWITCH.CONF(/etc/nsswitch.conf)It saves primarily name
service configuration information.
It functions as a policy/rules file for various resolution
namely: DNS, passwd(/etc/passwd, /etc/shadow),
group(/etc/group), protocols(/etc/inet/protocols), ethers or
mac-to-IP mappings, where to look for host resolution. The
figure below shows a sample nsswitch.conf file.
In the above nsswitch.conf file, the password and group
informational resolution is set to files which means the
system check for the local files like /etc/shadow,
/etc/passwd. For host name resolution which is set to files,
first hosts file(/etc/hosts) is checked and if it fails then
it is send to appropriate DNS server.
NTP(Network Time Protocol):
It synchronizes the local system and can be configured to
synchronize any NTP aware host.
Its hierarchical in design and supports from 1 to 16
28 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
strata(precision).
Stratum 1 servers are connected to external, more accurate
time sources such as GPS. Less latency results in more
accurate time.
NTP Client configuration:
xntpd or ntp service searches for /etc/inet/ntp.conf for
configuration file.
1. Copy ntp.client file as ntp.conf file: cp ntp.client
ntp.conf
2. Edit ntp.conf and make an entry for the NTP server : server
192.168.1.100
3. Enable ntp service: svcadm enable ntp
4.execute “date” command to check synchronization. The
synchronization can be done usingntpdate command as: ntpdate
<ServerName>
The command “ntpq -p <ServerName>”: This will query the remote
system time table. If we just give the command without
mentioning the server name, it will list the peers or server
for time sync. If we just run the “ntpq “ command, it will run
in interactive mode and if we type “help” in that mode it will
list various options that can be performed.
The command “ntptrace”: Traces path to the time source. If we
run it without any option it will default to local system. The
command “ntptrace <ServerName>” gives the path and stratum
details from the server mentioned to the local system.
NTP Server configuration:
1. We need to find the NTP pool site such
as: http://www.ntp.org/ . We will derive NTP public server
from their lists.
2. Once the list is derived, we need to make the entry of that
29 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
list in the file /etc/inet/ntp.conf as shown below:server
0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org3. Restart the NTP service: svcadm
restart ntp.
4. Making out NTP client machine as NTP server:
1. Go to /etc/inet: cd /etc/inet
2. Disable the NTP service: svcadm disable ntp
3. Copy the file ntp.server to ntp.conf: cp ntp.server
ntp.conf
4. Edit ntp.conf file: Make an entry into the file with the
servers list obtained from the NTP pool site and local server.
5. Comment the crontab entry for the ntpdate command.
1. crontab -e
2. Comment the line where ntpdate command is run.
6. Enable the NTP service: svcadm enable ntp
30 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Working with Files and Directories
Working with Files and Directories is very basic thing which
we dont want to miss while learning Solaris 10. Lets check few
very basic commands.
To display the current working directory:
pwd command: It displays the current working directory.
example:
#pwd
/export/home/ravi
To display contents of a directory:
ls command (Listing Command):It displays all files and
directories under the specified directory.
Syntax: ls -options <DirName>|<FileName>
The options are discussed as follows:
Option Description
p
It lists all the files & directories. The directory names are succeeded by the symbol
'/'
F
It lists all files along with their type. The symbols '/', '*', (None), '@' at the end of file
name represents directory, executable, Plain text or ASCII file & symbolic link
respectively
a It lists all the files & directories name including hidden files
l It lists detailed information about files & directories
t It displays all the files & directories in descending order of their modified time.
r It displays all the files & directories in reverse alphabetical order
R It displays all the files & directories & sub-directories in recursive order
i It displays the inode number of files & directories
tr It displays all the files & directories in the ascending order of their last modified date
Analysis of output of ls -l command:
ls -l → It list all the files and directories long list with
31 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
the permission and other information. The output looks as
follows:
FileType & Permissions LinkCount UID GID Size Last
ModifiedDate & ModifiedTime <File/Directory Name>
Following table explains the output:
Entry Description
FileType '-' for file & 'd' for directory
Permissions
Permissions are in order of Owner,
Group & Other
LinkCount Number of links to the file
UID Owner's User ID
GID Group's ID
Size Size of the file/directory
Last ModifiedDate &
ModifiedTime
Last Modified Date & Time of the
file/directory
<File/Directory Name> File/Directory name
Example:
# ls -l
total 6
-rw-r--r-- 1 root root 136 May 6 2010
local.cshrc
-rw-r--r-- 1 root root 167 May 6 2010
local.login
-rw-r--r-- 1 root root 184 May 6 2010
local.profile
Understanding permissions:
Following table explains the permission entry:
Entry Description
- No permission/denied
r read permission
w write permission
x execute permission
32 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
File Command: It is used to determine the file type. The
output of file command can be "text", "data" or "binary".
Syntax: file <file name>
Example:
# file data
data: English text
Changing Directories: 'cd' commad is used to change
directories.Syntax: cd <dir name>
If cd command is used without any option it changes the
directory from current working directory to user's home
directory.
Example: Let the user be 'ravi' and current working directory
is /var/adm/messages
#pwd
/var/adm/messages
#cd
#pwd
#/export/home/ravi
There is also a different way to navigate to the user's home
directory :
#pwd
/var/adm/messages
#cd ~ravi
#pwd
/export/home/ravi
#cd ~raju
#pwd
/export/home/raju
#cd ~ravi/dir1
33 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#pwd
/export/home/ravi/dir1
In the above examples, the '~' character is the abbreviation
that represents the absolute path of the user's home
directory. However this functionality is not available in all
shells.
There are few other path name abbreviations which we can use
as well. These are listed below :
. → current working directory
.. → Parent directory or directory above the current working
directory.
So if we want to go to the parent directory of the current
working directory following command is used:
#cd ..
We can also navigate multiple levels up in directory using cd,
.. and /.
Example: If you want to move two levels up the current working
directory, we will use the command :
#cd ../..
#pwd
/export/home/ravi
#cd ../..
#pwd
/export
#cd ..
#pwd
/
Viewing the files:
cat command: It displays the entire content of the file
34 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
without pausing.
Syntax: cat <file name>
Example:
#file data
data: English text
#cat data
This is an example for demonstrating the cat command.
#
Warning: The cat command should not be used to open a binary
file as it will freeze the terminal window and it has to be
closed. So check the file type using 'file' command, if you
are not sure about it.
more command: It is used to view the content of a long text
file in the manner of one screen at a time.
Syntax: more <file name>
The few scrolling options used with more command are as
follows :
Scrolling Keys Action
Space Bar Moves forward one screen
Return Scrolls one line at a time
b Moves back one screen
h Displays a help menu of features
/string searches forward for a pattern
n finds the next occurrence of the pattern
q quits and returns to shell prompt
head command: It displays the first 10 lines of a file by
default. The number of lines to be displayed can be changed
using the option -n. The syntax for the head command is as
follows:
Syntax: head -n <file name>
35 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
This displays the first n lines of the file.
tail command: It displays the last 10 lines of a file by
default. The number of lines to be displayed can be changed
using the options -n or +n.
Syntax:
#tail -n <file name>
#tail +n <file name>
The -n option displays the n lines from the end of the file.
The +n option displays the file from line n to the end of the
file.
Displaying line, word and character count:
wc command: It is used to display the number of lines, words
and characters in a given file.
Syntax: wc -options <file name>
The following option can be used with wc command:
Option Description
l Counts number of lines
w Counts number of words
m Counts number of characters
c Counts number of bytes
Example:
#cat data
This is an example for demonstrating the cat command.
#wc -w data
9
Copying Files:
cp command: It can be used to copy file/files.
Syntax:cp -option(s) surce(s) destination
The options for the cp command are discussed below :
36 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Option Description
i
Prevents the accidental overwriting of existing files or
directories
r
Includes the contents of a directory, including the
contents of all sub-directories, when you copy a
directory
Example:
#cp file1 file2 dir1
In the above example file1 and file2 are copies to dir1.
Moving & renaming files and directories:
mv command: It can be used to
1. Move files and directories within the directory hierarchy :
Example: We want to move file1 and file2 under the directory
/export/home/ravi to /var
#pwd
/export/home/ravi
#mv file1 file2 /var
2. Rename existing files and directories.
Example: we want to rename file1 under /export/home/ravi to
file2.
#pwd
/export/home/ravi
#mv file1 file2
The mv command does not affect the contents of the files or
directories being moved or renamed.
We can use -i option with the mv command to prevent the
accidental overwriting of the file.
Creating files and directories :
touch Command : It is used to create an empty file. We can
create multiple file using this command.
Syntax: touch <files name>
Example: #touch file1 files2 file3
mkdir command : It is used to create directories.
Syntax: mkdir -option <dir name>
When the <dir name> includes a pah name, option -p is used to
create all non-existing parent directory.
37 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Example:
#mkdir -p /export/home/ravi/test/test1
Removing Files and Directories :
rm command: It is used permanently remove files/directories.
The Syntax:rm -option <file name>/<dir name>
The -i option is used to prompt user for confirmation before
the deletion of files/directories.
Example: We want to remove file1 and file2 from the home
directory of user ravi.
#pwd
/
#cd ~ravi
#pwd
/export/home/ravi
#rm file1 file2
Note: The removal of a directory is slightly different. If the
directory is not empty and you are trying to delete it, you
will not be able to do so. You need to use -r option to remove
the directory with files and sub-directories.
Example: We want to delete a directory test under user ravi
home directory and it contains file and sub-directories.
#pwd
/export/home/ravi
#rm test
rm: test is a directory
#rm -r test
#
To remove an empty directory:
Syntax: rmdir <directory name>
Links (Soft Link and Hard Link) : This section has been
covered under section :Solaris File System. Please refer to
it.
Searching Files, Directories & its contents:
Using the grep command : The grep is very useful and widely
used command.
lets take an example where we want to see if the process statd
is running of not. Following command is used :
#ps -ef | grep statd
# ps -ef | grep statd
daemon 2557 1 0 Jul 07 ? 0:00
/usr/lib/nfs/statd
38 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
root 10649 1795 0 05:29:39 pts/4 0:00 grep statd
#
Syntax: grep options filenames.
The options used are discussed below :
i Searches both uppercase and lowercase characters
l Lists the name of files with matching lines
n Precedes each line with the relative line number in the file
v Inverts the search to display lines that do not match pattern
c Counts the lines that contain pattern
w
Searches for the expression as acomplete word, ignoring those
matches that are sub strings of larger words
Lets see few examples:
Suppose we want to search for all lines that contain the
keyword root in /etc/group file and view their line numbers,
we use following option :
# grep -n root /etc/group
1:root::0:
2:other::1:root
3:bin::2:root,daemon
4:sys::3:root,bin,adm
5:adm::4:root,daemon
6:uucp::5:root
7:mail::6:root
8:tty::7:root,adm
9:lp::8:root,adm
10:nuucp::9:root
12:daemon::12:root
To search for all the lines that does not contain the keyword
root:
# grep -v root /etc/group
staff::10:
sysadmin::14:
smmsp::25:
gdm::50:
webservd::80:
postgres::90:
unknown::96:
nobody::60001:
noaccess::60002:
nogroup::65534:
cta::101:
rancid::102:
mysql::103:
torrus::104:
To search for the names of the files that contains the keyword
39 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
root in /etc directory :
# cd /etc
# grep -l root group passwd hosts
group
passwd
To count the number of lines containing the pattern root in
the /etc/group file:
# grep -c root group
11
Using regular expression Metacharacters with grep command:
Metachar Purpose Example Result
^
Begining of line
Anchor
'^test'
Matches all lines
begining with test
$
End of line
anchor
'test$'
Matches all the lines
ending with test
. Matches one char 't..t'
Matches all the line
starting and ending with
t and 2 char between them
*
Matches the
preceding item 0
or more times
'[a-s]*'
Matches all lines
starting with lowercase
a-s
[]
Matches one
character in the
pattern
'[Tt]est'
Matches lines containing
test ot Test
[^]
Matches one
character not in
pattern
'[^a-
s]est'
Matches lines that do not
contain "a" though "s"
and followed by est
Using egrep command :
With egrep we can search one or more files for a pattern using
extended regular expression metacharacters.
Following table describes the Extended Regular Expression
Metacharacters :
Metachar Purpose Example Result
+
Matches one
of more
preceding
chars
'[a-z]+est'
Matches one or more
lowercase letters
followed by est(for
example chest, pest,
best, test, crest etc
x|y Matches 'printer|scanner' Matches for either
40 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
either x or
y
expression
(|)
Groups
characters
'(1|2)+' or
'test(s|ing)'
Matches for one or
more occurrence.
Syntax: egrep -options pattern filenames
Examples:
#egrep '[a-z]+day' /ravi/testdays
sunday
monday
friday
goodday
badday
In the above example, we searched for the letter ending with
day in the file /ravi/testdays
#egrep '(vacation |sick)' leave' /ravi/leavedata
vacation leave on 7th march
sick leave on 8th march
In the above example we are displaying sick leave and vacation
leave from file /ravi/leavedata
Using fgrep command :
It searches for all the character regardless of it being
metacharacter as we have seen in case of grep and egrep
commands.
Syntax: fgrep options string filenames
Example:
#fgrep '$?*' /ravi/test
this is for testing fgrep command $?*
#
Using Find command :
This command is used to locate files and directories. You can
relate it with windows search in terms of functionality.
Syntax: find pathnames expressions actions
Pathname: The absolute or relative path from where the search
begins.
Expressions: The search criteria is mentioned here. We will
discuss search criteria below in details.
Expression Definition
-name
filename
Finds the file matching.
-size [+|-]n Finds files that are larger than +n, smaller than
41 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
-n, or exactly n.
-atime [+|-
]n
Find files that have been accessed more than +n
days, less than -n or exactly n days ago.
-mtime [+|-
]n
Find files that have been modified more than +n
days, less than -n or exactly n days ago.
-user
loginID
Finds all files that are owned by the loginID
name.
-type Finds a file type : f for file, d for directory.
-perm
Find files that have certain access permission
bits.
Action: Action required after all the files have been found.
By default it displays all the matching pathnames
Action Definition
-exec
command {}
;
Runs the specified command on each file located.
-ok
commadn {}
:
Requires confirmation before the find command
applies the command to each file located.
-print Prints the search result
-ls
Displays the current pathname and associated stats
: inode number, size in kb, protection mode, no. of
hard links and the user.
-user
loginID
Finds all files that are owned by the loginID name.
-type Finds a file type : f for file, d for directory.
-perm
Find files that have certain access permission
bits.
Examples:
#touch findtest
#cat >> findtest
This is for test.
#find ~ -name findtest -exec cat {} ;
This is for test.
#
The above examples searches for the file : findtest and
displays its content. We can also use 'ok' option instead of
exec. This will prompt for confirmation before displaying the
contents of file findtest.
If we want to find files larger than 10 blocks (1 block =
512bytes) starting from /ravi directory, following command is
42 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
used :
#find /ravi -size +10
If we want to see all files that have not been modified in the
last two days in the directory /ravi, we use :
#find /ravi -mtime +2
Printing Files:
lp comand : This command is located in /usr/bin directory. It
is used to submit the print request to the printer.
Syntax:
/usr/bin/lp <file name>
/usr/bin/lp -d <printer name > <file name>
The options for the lp command are discussed below :
Option Description
d
It is used to specify the desired printer. It is not
required if default printer is used
o
It is used to specify that the banner page should not be
printed
n Print the number of copies specified
m It send email after the print job is complete
lpstat command : It displays the status of the printer queue.
The Syntax for this command is as follows:
lpstat -option <printer name>
The options for the lpstat command are discussed below :
Option Description
p Displays the status of all printers
o Displays the status of all output printers
d Displays the default system printer
t Displays the complete status information of all printers
s Display the status summary of all printers
a Displays which printers are accepting request
The output of the lpstat command is in the following format :
<request ID> <user ID> <File Size> <Date & Time> <status>
Cancel command : It is used to cancel the print
request. The Syntax:
cancel <request ID>
43 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
cancel -u <user name>
Note: We can use lpstat command to get the request ID.
VI Editor
VI Editor (Visual Editor)
Its an editor like notepad in windows which is used to edit a
file in SOLARIS. Unlike notepad it is very difficult to use. I
wish the VI editor would have been developed by Bill
gates rather than Bill Joy. Anways, guys we dont have any
other option rather than getting aware of all these commands
so that we become proficient in working with the VI Editor.
Here are few commands that can be used while working with VI
editor.
There are three command modes in VI editor and we will see the
commands based on the modes.
Command Mode :
This is default mode of the VI editor. In this mode we can
delete, change, copy and move text.
Navigation:
Key Use
j(or down
arrow)
To move the cursor to the next line (move down)
k(or up
arrow)
To move the cursor to the previous line (move
up)
h(or left
arrow)
To move left one character
l(or right
arrow)
To move right one character
H
To move the cursor to current page beginning of
the first line.
G To move the cursor to current page beginning of
44 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
the last line.
b To move the cursor previous word first character
e To move the cursor next word last character
w To move the cursor to next word first character
^ Go to beginning of line
0 Go to beginning of line
$ Go to the end of the line
CTRL+F forward 1 screen
CTRL+B backward 1 screen
CTRL+D down (forward) 1/2 screen
CTRL+U up (backward) 1/2 screen
Copy & Paste:
Key Use
y+w
To copy rest of the word from current cursor
position.
n+y+w
To copy n number of words from the current cursor
position.
y+y To copy a line
n+y+y To copy n lines
p(lowerCase)
To paste a copied words/lines after the current
position of the cursor
P(uppercase)
To paste a copied words/lines before the current
position of the cursor
Deletion:
Key Use
x deletes a single character
n+X
To delete n number of characters from the cursor
position in a line.
d+w To delete rest of a word from current cursor position
n+d+w
To delete n number of words from the cursor position in
a line
d$ Delete rest of line from current cursor position
D Delete rest of line from current cursor position
d+d To delete an entire line
n+d+d To delete n lines from current cursor position
45 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Few More Important Command Mode commands:
Key Use
u Undo changes (only one time)
U Undo all changes to the current line
~ To change the case of the letter
ZZ Saves the changes and quits the vi editor
Input or Insert Mode: In this mode we can insert text into the
file. We can enter the insert mode by pressing following keys
in command mode:
Key Use
i Inserts the text before the cursor
I Inserts the text at the beginning of the line
o Opens a new blank line below the cursor
O Opens a new blank line above the cursor
a Appends text after the cursor
A Appends the text after the line
r replace the single character with another character
R replace a entire line
Esc To return to command mode
Last line mode or Collan Mode : This is used for advance
editing commands. To access the last line mode enter ":" while
in command mode.
Key Use
:
To get to collan mode(This need to be entered every time a
user wants to use collan mode command)
:+set nu Shows line numbers
:+set nonu Hides line numbers
46 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
:+enter+n Moves the cursor to the n line
:+/keyword
To move the cursor to the line starting with the specific
keyword
:+n+d Deletes nth line
:+5,10d Delete line from 5th line to 10th line
:+7 co 32 Copies 7th line and paste in 32nd line
:+10,20 co 35
Copies lines from 10th line to 20th line and paste it from
35th line
:+%s/old_text/new_text/g
Searches old string and replaces with
the new string
:+q+! Quits vi editor without saving
:+w Saves the file with changes by writing to the disk
:+w+q Saving and exit the vi editor
:+w+q+! Saving and quitting the file forcefully
1,$s/$/" -
type=Text_to_be_appended
Append text at the end of the line
Using VI Command:
vi options <file name>
The options are discussed below:
-r : To recover a file from system crash while editing.
-R : To open a file in read only mode.
Viewing Files in Read Only Mode:
view <file name>
This is also used to open the file in read only mode. To exit
type ':q' command.
Automatic Customization of a VI session:
1. Create a file in the user's home directory with the name
.exrc
2. enter the set variables without preceding colon
3. Enter each command in one line.
47 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
VI reads the .exrc file each time the user opens the vi
session.
Example:
#cd ~
#touch .exrc
#echo "set nu">.exrc
#cat .exrc
set nu
#
In the above example we have used set line number command. So
whenever the user opens the vi session, line number is
displayed.
48 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Working with Shell
In this section we will play with shell.
Shell is an interface between a user and the kernel. It is a
command interpreter which interprets the commands entered by
user and sends to kernel.
The Solaris shell supports three primary shells:
Bourne Shell:
It is original UNIX system shell.
It is default shell for root user.
The default shell prompt for the regular user is $ and root is
#.
C Shell:
It has several features which bourne shell do not have.
The features are:
It has command-line history, aliasing, and job control.
The shell prompt for regular user is hostname% and for root
user hostname#.
Korn Shell:
It is a superset of Bourne Shell with C shell like
enhancements and additional features like command history,
command line editing, aliasing & job control.
Alternative shells:
Bash(Bourne Again shell): It is Bourne compatible shell that
incorporates useful features from Korn and C shells, such as
command line history and editing and aliasing.
Z Shell: It resembles Korn shell and includes several
enhancements.
TC Shell: It is completely compatible version of C shell with
additional enhancements.
Shell Metacharacters:
49 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Lets understand Shell Metacharacters before we can proceed any
further. These are the special characters, generally symbols
that has specific meaning to the shell.There are three types
of metacharacters:
1. Pathname metacharacter
2. File name substitution metacharacter
3. Redirection metacharacter
Path Name Metacharacters:
Tilde (~) character: The '~' represents the home directory of
the currently logged in user.It can be used instead of the
user's absolute home path.Example : Lets consider ravi is the
currently logged in user.
#pwd
/
#cd ~
#pwd
/export/home/ravi
#cd ~/dir1
#pwd
/export/home/ravi/dir1
#cd ~raju
#pwd
/export/home/raju
Note: '~' is available in all shells except Bourne shell.
Dash(-) character: The '-' character represents the previous
working directory.It can be used to switch between the
previous and current working directory.
Example:
#pwd
/
#cd ~
#pwd
50 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
/export/home/ravi
#cd -
#pwd
/
#cd -
#pwd
/export/home/ravi
File Name Substitution Metacharacters :
Asterisk (*) Character: It is a called wild card character and
represents zero or more characters except for leading period
'.' of a hidden file.
#pwd
/export/home/ravi
#ls dir*
dir1 dir2 directory1 directory2
#
Question Mark (?) Metacharacters: It is also a wild card
character and represents any single character except the
leading period (.) of a hidden file.
#pwd
/export/home/ravi
#ls dir?
dir1 dir2
#
Compare the examples of Asterisk and Question mark
metacharacter and you will get to know the difference.
Square Bracket Metacharacters: It represents a set or range of
characters for a single character position.
The range list can be anything like : [0-9], [a-z], [A-Z].
#ls [a-d]*
apple boy cat dog
51 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#
The above example will list all the files/directories starting
with either 'a' or 'b' or 'c' or 'd'.
#ls [di]*
dir1 dir2 india ice
#
The above example will list all the files starting with either
'd' or 'i'.
Few shell metacharacters are listed below:
Metacharacter Description
~
The '~' represents the home directory of the
currently logged in user
-
The '-' character represents the previous working
directory
*
A wild card character that matches any group of
characters of any length
?
A wild card character that matches any single
character
$
Indicates that the following text is the name of
a shell (environment) variable whose value is to
be used
|
Separates command to form a pipe and redirects
the o/p of one command as the input to another
< Redirect the standard input
>
Redirect the standard output to replace current
contents
>>
Redirect the standard output to append to current
contents
;
Separates sequences of commands (or pipes) that
are on one line

Used to "quote" the following metacharacter so it
is treated as a plain character, as in *
& Place a process into the background
Korn Shell Variables: It is referred to as temporary storage
area in memory.It enables us to store value into the variable.
These variables are of two types :
52 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
1. Variables that are exported to subprocesses.
2. Variables that are not exported to subprocesses.
Lets check few commands to work with these variables:
To set a variable :
#VAR=value
#export VAR
Note: There is no space on the either side of the '=' sign.
To unset a variable:
#unset VAR
To display all variables:
We can use 'set' or 'env' or 'export' command.
To display value of a variable:
echo $VAR or print $VAR
Note: When a shell variable follows $ sign, then the shell
substitutes it by the value of the variable.
Default Korn Shell Variables :
EDITOR : The default editor for the shell.
FCEDIT : It defines the editor for the fc command.
HOME : Sets the directory to which cd command switches.
LOGNAME : Sets the login name of the user.
PATH : It specifies the paths where shell searches for a
command to be executed.
PS1 :It specifies the primary korn shell ($)
PS2 : It specifies the secondary command prompt (>)
SHELL : It specifies the name of the shell.
Using quoting characters:
Quoting is the process that instructs the shell to mask/ignore
the special meaning of the metacharacters. Following are few
53 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
use of the quoting characters:
Single quotation mark (''): It instructs the shell to ignore
all enclosed metacharacters.
Example:
#echo $SHELL
/bin/ksh
#echo '$SHELL'
$SHELL
#
Double quotation mark (""): It instructs the shell to ignore
all enclosed shell metacharacters, except for following :
1. The single backward quotation(`) mark : This executes the
solaris command inside the single quotation.Example:
# echo "Your current working directory is `pwd`"
Your current working directory is /export/home/ravi
In the above example the '`' is used to execute the 'pwd'
command inside the quotation mark.
2. The blackslash() in the front of a metacharacter : This
ignores the meaning of the metacharacter.Example:
#echo "$SHELL"
/bin/ksh
#echo "$SHELL"
$SHELL
In the above example, the inclusion of '' ignores the meaning
of metacharacter '$'
3. The '$' sign followed by command inside parenthesis : This
executes the command inside the parenthesis.Example:
# echo "Your current working directory is $(pwd)"
Your current working directory is /export/home/ravi
In the above example enclosing the pwd command inside
54 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
parenthesis and $ sign before parenthesis, executes the pwd
command.
Displaying the command history:
The shell keeps the history of all the commands entered. We
can re-use this command in our ways. For a given user this
list of command used is shared among all the korn shells.
Syntax: history option
The output will somewhat like following :
...
125 pwd
126 date
127 uname -a
128 cd
The numbers displayed on the left of the command are command
numbers and can be used to re-execute the command
corresponding to it.To view the history without command number
-n option is used : #history -n
To display the last 5 commands used along with the current
command :
#history -5
To display the list in reverse order:
#history -r
To display most recent pwd command to the most recent uptime
command, enter the following:
#history pwd uptime
Note: The Korn shell stores the command history in file
specified by the HISTFILE variable. The default is the
~/.sh_history file. By default shell stores most recent 128
commands.
Note: The history command is alias for the command "fc -l".
The 'r' command :
The r command is an alias in Korn Shell that enables us to
repeat a command.
Example:
#pwd
/export/home/ravi
55 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#r
/export/home/ravi
This can be used to re-execute the commands from history.
Example:
#history
...
126 pwd
127 cd
128 uname -a
#r 126
/export/home/ravi
The 'r' command can also be used to re-execute a
command beginning with a particular character, or string of
characters. Example:
# r p
pwd
/export/home/ravi
#
In the above example the 'r' command is used to re-run the
most recent occurrence of the command starting with p.
#r ps
ps -ef
o/p of ps -ef command
In the above example the 'r' command is used to re-run the
most recent command starting with ps.
We can also edit the previously run command according to our
use. The following example shows that :
#r c
cd ~/dir1
#r dir1=dir
cd ~/dir
In this example the cd command has re-run but the argument
passed to it has been changed to dir from dir1.
56 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Note: The r command is alias for the command " fc -e - ".
Editing the previously executed commands using vi-editor :
We can also edit the previously executed command under history
using vi-editor. To do so, we need to enable shell history
editing by using any one of the following commands :
#set -o vi
or
#export EDITOR=/bin/vi
or
#export VISUAL=/bin/vi
To verify whether this feature is turned on, use the following
command :
#set -o | grep -w vi
vi on
Once it is on you can start editing the command history as
follows :
1. Execute the history command: #history
2. Press Esc key and start using the vi editing options.
3. To run a modified command, press enter/return key.
File Name Completion :
Suppose you are trying to list files under the directory
"/directoryforlisting". This is too big to type. There is a
short method to list this directory.
Type ls d and then press Esc and then  (backslash) key. The
shell completes the file name and will display :
#ls directoryforlisting/
We can also request to display all the file
name beginning with 'd' by pressing Esc and = key
57 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
sequentially.
Two points to be noted here :
1. The key sequence presented above works only in the vi mode
of the command line editing.
2. The sequence in which the key is pressed is important.
Command Redirection:
There are two redirection commands:
1. The greater than (>) sign metacharacter
2. The less than (<) sign metacharacter
Both the above mentioned mentioned commands are implied by
pipe (|) character.
The File Descriptors:
Each process works with shell descriptor. The file descriptor
determines where the input to command originates and where the
output and error messages are sent.
File Descriptor
Number
File Description
Abbreviation
Definition
0 stdin
Standard Command
input
1 stdout
Standard Command
output
2 stderr
Standard Command
error
All command that process file content read from the standard
input and write to standard output.
Redirecting the standard Input:
command < filename or command 0<filename
The above command the "command" takes the input from
"filename" instead of keyboard.
58 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Redirecting the standard Output:
command > filename or command 1>filename
#ls -l ~/dir1 > dirlist
The above command redirects the output to a file 'dirlist'
instead of displaying it over the terminal.
command >> filename
#ls -l ~/dir1 >> dirlist
The above example appends the output to the file 'dirlist'.
Redirecting the Standard Error:
command > filename 2> <filename that will save error>
command> filename 2>&1
The first example will redirect the error to the file name
specified at the end.
The second example will redirect the error to the input file
itself.
The Pipe character :
The pipe character is used to redirect the output of a command
as input to the another command.
Syntax: command | command
Example:
# ps -ef | grep nfsd
In the above example the output of ps -ef command is send as
input to grep command.
#who | wc -l
User Initialization Files Administration :
In this section we will see initialization files of Bourne,
Korn and C shell.
Initialization files at Login
/bin/ksh
Shell
System wide
Initializati
Primary
user Initialization F
User
Initializati
Shell
Pathnam
59 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
on File ile Read at Login on Files
Read When a
New Shell is
Started
e
Bourn
e
/etc/profile $HOME/.profile /bin/sh
Korn /etc/profile $HOME/.profile $HOME/.kshrc
/bin/ks
h
$HOME/.kshrc
C /etc/.login $HOME/.cshrc $HOME/.cshrc
/bin/cs
h
$HOME/.login
Bourne Shell Initialization file:
The .profile file in the user home directory is
an initialization file which which shell executes when the
user logs in. It can be used to a) customize the terminal
settings & environment variables b)instruct system to initiate
an application.
Korn Shell Initialization file: It has two initialization file
:
1. The ~/.profile: The .profile file in the user home
directory is an initialization file which which shell executes
when the user logs in. It can be used to a) customize the
terminal settings & environment variables b)instruct system to
initiate an application.
2. The ~/.kshrc: It contains shell variables and aliases. The
system executes it every time the user logs in and when a ksh
sub-shell is started. It is used to define Korn shell specific
settings. To use this file ENV variable must be defined in
.profile file.
Following settings can be configured in /.kshrc file :
Shell prompt definations (PS1 & PS2)
Alias Definitions
60 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Shell functions
History Variables
Shell option ( set -o option)
The changes made in these files are applicable only when the
user logs in again. To make the changes effective immediately,
source the ~/.profile and ~/.kshrc file using the dot(.)
command:
#. ~/.profile
#. ~/.kshrc
Note: The /etc/profile file is a separate system wide file
that system administrator maintains to set up tasks for every
user who logs in.
C Shell Initialization file: It has two initialization file :
1. The ~/.cshrc file : The . cshrc file in the user home
directory is an initialization file which which shell executes
when the user logs in. It can be used to a) customize the
terminal settings & environment variables b)instruct system to
initiate an application.
Following settings can be configured in .cshrc file :
Shell prompt definations (PS1 & PS2)
Alias Definitions
Shell functions
History Variables
Shell option ( set -o option)
2. The ~/.login file: It has same functionality as .cshrc file
and has been retained for legacy reasons.
Note: The /etc/.login file is a separate system wide file that
system administrator maintains to set up tasks for every user
who logs in.
The changes made in these files are applicable only when the
user logs in again. To make the changes effective immediately,
61 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
source the ~/.cshrc and ~/.login file using the source
command:
#source ~/.cshrc
#source ~/.login
The ~/.dtprofile file : It resides in the user home directory
and determines generic and customized settings for the desktop
environment.The variable setting in this file can overwrite
the default desktop settings. This file is created when the
user first time logs into the desktop environment.
Important: When a user logins to the desktop environment, the
shell reads .dtprofile, .profile and .kshrsc file
sequentially. If the DTSOURCEPROFILE variable under .dtprofle
is not ture or does not exists, the .profile file is not read
by the shell.
The shell reads .profile and .kshrsc file when user opens
console window.
The shell reads .kshrsc file when user opens terminal window.
Configuring the $HOME/.profile file:
It can be configured to instruct the login process to execute
the initialization file referenced by ENV variable.
To configure that we need to add the following into the
$HOME/.profile file:
ENV=$HOME/.kshrc
export ENV
Configuring the $HOME/.kshrc file :
This file contains korn shell specific setting.To configure
PS1 variable, we need to add the following into the
$HOME/.kshrc file:
PS1="''hostname' $"
export PS1
62 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Advanced Shell Functionality:
In this module we will learn four important aspects of Korn
shell.
Managing Jobs in Korn Shell:
A job is a process that the shell can manage. Each job has a
process id and it can be managed and controlled from the
shell.
The following table illustrates the job control commands:
Command Value
jobs
List all jobs that are currently running or
stopped in the background
bg %<jobID> Runs the specified job in background
fg %<jobID> Brings the specified job in foreground
Ctrl+Z
Stops the foreground job and places it in the
background as a stopped job
stop
%<jobID>
Stops a job running in background
Note: When a job is placed either in foreground or background,
the job restarts.
Alias Utility in Korn Shell :
Aliases in Korn shell can be used to abbreviate the commands
for the ease of usage.
Example:
we are frequently using the listing command: ls -ltr. We can
create alias for this command as follows:
#alias list='ls -ltr'
Now when we type the 'list' over shell prompt and hit return,
it replaces the 'list' with the command 'ls -ltr' and executes
it.
Syntax : alias <alias name>='command string'
Note:
1. There should not be any space on the either side of the '='
sign.
2. The command string mustbe quoted if it includes any
options, metacharacters, or spaces.
3. Each command in a single alias must be separated with a
semicolon.e.g.:#alias info='uname -a; date'
The Korn shell has predefines aliases as well which can be
listed by using 'alias' command:
#alias
..
63 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
stop='kill -STOP'
suspend='kill -STOP $$'
..
Removing Aliases:
Syntax: unalias <alias name>
Example:
#unalias list
Korn Shell functions :
Function is a group of commands organized together as
a separate routine. Using a function involves two steps :
1. Define the function:
function <function name> { command;...command; }
A space must appear after the first brace and before the
closing brace.
Example:
#function HighFS{ du -ak| sort -n| tail -10; }
The above example defines a function to check the top 10 files
using most of the space under current working directory.
2. Invoke the function :
If we want to run the above defined function, we just need to
call it by its name.
Example:
#HighFS
6264 ./VRTSvcs/conf/config
6411 ./VRTSvcs/conf
6510 ./VRTSvcs
11312 ./gconf/schemas
14079 ./gconf/gconf.xml.defaults/schemas/apps
16740 ./gconf/gconf.xml.defaults/schemas
17534 ./gconf/gconf.xml.defaults
28851 ./gconf
40224 ./svc
87835 .
Note: If a function and an alias are defined by the same name,
alias takes precedence.
To view the list of all functions :
#typeset -f -> This will display functions as well as their
definitions.
#typeset +f -> This will display functions name only.
Configuring the Shell Environment variable:
The shell secondary prompt sting is stored in the PS2 shell
variable, and it can be customized as follows:
#PS2="Secondary Shell Prompt"
#echo PS2
64 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Secondary Shell Prompt
#
To display the secondary shell prompt in every shell, it must
be included in the user's Korn Shell initialization
file(.kshrc file)
Setting Korn Shell options :
Korn Shell options are boolean (on or off). Following is the
Syntax:
To turn on an option:
#set -o option_name
To turn off an option:
#set +o option_name
To display current options:
# set -o
Example:
#set -o noclobber
#set -o | grep noclobber
noclobber on
The above example sets the noclobber option. When this option
is set, shell refuses to redirect the standard output to a
file and displays error message on the screen.
#df -h > DiskUsage
#vmstat > DiskUsage
ksh: DiskUsage: file already exists
#
To deactivate the noclobber option :
#set +o noclobber
Shell Scripts:
It is a text file that has series of command executed one by
one. There are different shell available in Solaris. To ensure
that the correct shell is used to run the script, it should
begin with the characters #! followed immediately by the
absolute pathname of the shell.
#!/full_Pathname_of_Shell
Example:
#!/bin/sh
#!/bin/ksh
Comments: It provides information about the script
files/commands. The text inside the comment is not executed.
The comment starts with character '#'.
lets write our first shell script :
65 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
#cat MyFirstScript
#!/bin/sh
ls -ltr #This is used to list the files/directories
Running a Shell Script :
The shell executes the script line by line. It does not
compile the script and keep it in binary form. So, In order to
run a script, a user must have read and execute permission.
Example:
#./MyFirstScript
The above example runs the script in sub-shell. If we want to
run the script as if the commands in it were ran in same
shell, the dot(.) command is used as follows:
#. ./MyFirstScript
Passing Value to the shell script:
We can pass value to the shell script using the pre-defined
variables $1, $2 and so on. These variables are called
Positional Parameters. When the user run the shell script, the
first word after the script name is stored in $1, second in $2
and so on.
Example:
#cat welcome
#!/bin/sh
echo $1 $2
#welcome ravi ranjan
ravi ranjan
In the above example when we ran the script welcome, the two
words after it ravi and ranjan was stored in $1 and $2
respectively.
Note: There is a limitation in Bourne shell. It accepts only a
single number after $ sign. So if we are trying to access the
10th argument $10, it will result in the value of $1 followed
by (0).
In order to overcome this problem, shift command is used.
Shift Command:
It enables to shift the value of positional parameter values
back by one position i.e. the value of $2 parameter is
assigned to $1, and $3 to $2, and so on.
Checking Exit status:
All commands under Solaris returns an exit status. The value
'0' indicates success and non-zero value ranging from 1-255
represents failure. The exit status of the last command run
under foreground is held in ? special shell variable.
# ps -ef | grep nfsd
root 6525 22601 0 05:55:01 pts/11 0:00 grep nfsd
66 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
# echo ?
1
#
In the above example there is no nfsd process running, hence 1
is returned.
Using the test Command:
It is used for testing conditions. It can be used to verify
many conditions, including:
Variable contents
File Access permissions
File types
Syntax : #test expression or #[ expression ]
The test builtin command returns 0 (True) or 1 (False),
depending on the evaluation of an expression, expr.
Syntax:test expr or [ expr ]
We can examine the return value by displaying $?;
We can use the return value with && and ||; or we can test it
using the various conditional constructs.
We can compare arithmetic values using one of the following:
Option Tests for Arithmetical Values
-eq equal to
-ne not equal to
-lt less than
-le less than or equal to
-gt greater than
-ge greater than or equal to
We can compare strings for equality, inequality etc. Following
table lists the various options that can be used to compare
strings:
Option Tests for strings
=
equal to.
e.g #test "string1" = "string2"
!=
not equal to.
e.g #test "string1" = "string2"
<
less than.
e.g #test "ab" < "cd"
67 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
>
greater than.
e.g #test "ab" > "cd" "
-z
for a null string.
e.g #test -z "string1"
-n
returns True if a string is not empty.
e.g. #test -n "string1"
Note: the < and > operators are also used by the shell for
redirection, so we must escape them using < or >.
Example :
Lets test that the value of variable $LOGNAME is ravi.
#echo $LOGNAME
ravi
# test "LOGNAME" = "ravi"
#echo $?
0
#[ "LOGNAME" = "ravi" ]
#echo $?
0
Lets test if read permissions on the /ravi
#ls -l /ravi
-rw-r--r-- 1 root sys 290 Jan 10 01:10 /ravi
#test -r /ravi
#echo $?
0
#[ -r /ravi ]
#echo $?
0
Lets test if /var is a directory
#test -d /var
#echo $?
0
#[ -d /var ]
#echo $?
0
68 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Executing Conditional Commands :
In this section we will see the following three conditional
commands:
1. Using If command: It checks for the exit status of the
command and if exist status is (0), then the statement are run
other wise statement under else is executed.
Syntax:
#if command1
>then
>execute command2
>else
>execute command3
>fi
The shell also provides two constructs that enable us to run
the command based on the success or failure of the preceding
command.
The constructs are &&(and) and ||(or).
Example:
#mkdir /ravi && /raju
This command creates directory /raju only if /ravi is created.
#mkdir /ravi || /raju
This command creates directory /raju even if /ravi fails to
create.
2. Using while command: It enables to repeat a command or
group of command till the condition returns (0).
Syntax:
#while command1
>do
>command2
>done
3. Using case command: It compares a single value against
other values and runs a command or commands when a match is
found.
Syntax:
#case value in
>pat1)command
>command
>..
>command
>;;
>pat2)command
>command
>..
>command
>;;
...
69 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
>patn)command
>command
>..
>command
Process Management
Process: Every program in Solaris runs as a process and there
is a unique PID attached with each process. The process
started/run by OS is called Daemon. It runs in background and
provides services.
Each process has a PID, UID and GID associated with it. UID
indicates the user who owns the process and GID denotes the
group to which owner belongs to.
When a process creates another process, then the new process
is called Child Process and old one is called Parent Process.
Viewing Process:
ps command: It is used to view process and is discussed below.
Syntax: ps options
Few options are discussed below:
Option Description
-e
Prints info about every process on the system including
PID, TTY(terminal identifier), TIme & CMD
-f
Full verbose listing which includes UIDm parent PID,
process start time(STIME)
Example:
#ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 Jun 02 ? 2:18
sched
root 1 0 0 Jun 02 ? 1:47
/sbin/init
root 2 0 0 Jun 02 ? 0:13
pageout
root 3 0 0 Jun 02 ? 110:25
fsflush
daemon 140 1 0 Jun 02 ? 0:15
/usr/lib/crypto/kcfd
root 7 1 0 Jun 02 ? 0:28
/lib/svc/bin/svc.startd
--More--
70 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Now let us understand the above output column wise :
Column Description
UID User Name of the process owner
PID Process ID
PPID Parent Process ID
C The CPU usage for scheduling
STIME Process start time
TTY
The controlling terminal for process. For daemons '?' is
displayed as it is started without any terminal.
TIME The cumulative execution time for the process.
CMD The command name, options, arguments
We can also search specific process using ps and grep command.
For Example, if we want to search for nfsd process, we using
the following command :
-sh-3.00$ ps -ef | grep nfsd
daemon 2127 1 0 Jul 06 ? 0:00
/usr/lib/nfs/nfsd
ravi 26073 23159 0 03:05:49 pts/175 0:00 grep nfsd
-sh-3.00$
pgrep command: It is used to search process by process name
and displays PID of the process.
Syntax : pgrep options pattern
The options are described below:
Option Description
-x Displays the PID that matches exactly
-n
Displays only the most recently created PID that
matches the pattern
-U uid
Displays only the PIDs that belong to the specific
user. This option uses either a user name or a UID
-l Displays the name of the process along with the PID
-t
term
Displays only those processes that are associated with
a terminal in the term list
Examples:
-sh-3.00$ pgrep j
3440
1398
-sh-3.00$ pgrep -l j
71 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
3440 java
1398 java
-sh-3.00$ pgrep -x java
3440
1398
-sh-3.00$ pgrep -n java
1398
-sh-3.00$ pgrep -U ravi
28691
28688
Using the ptree command:
It displays a process tree based on the process ID passed as
an argument.
An argument of all digits are taken to be a PID, otherwise it
is assumed to be a user login name.
Sending a Signal to a process:
Signal is a messages that is send to a process. The process
responds back by performing the action that the signal
requests. It is identified by a signal number and by a signal
name. There is an action associated to each signal.
Signal
No.
Signal
Name
Event Definition
Default
Response
1 SIGHUP Hang Up
It drops a telephone line
or terminal connection. It
also causes some program to
re-intialize itself without
terminating
Exit
2 SIGINT Interrupt
Its it generated from Key
board. e.g. ctrl+C
Exit
9 SIGKILL Kill
It kills the process and a
process cant ignore this
signal
Exit
15 SIGTERM Terminate
It terminates the process
in orderly manner. This is
the default signal that
kill & pkill send.
Exit
Using kill Command: It is used to send signal to one or more
processes and terminates only those process that is owned by
the user. A root user can kill any process. This command sends
signal 15 to the process.
72 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
Syntax: kill [-signals] PIDs
Examples:
# pgrep -l java
2441 java
#kill 2441
If the process does not terminates, issue signal 9 to
forcefully terminate the process as below :
#kill -9 2441
Using pkill Command: It is used to terminate the process with signal
15. We can specify the process names(to be terminated) also in this
command.
Syntax: pkill [-options] pattern
The options are same as that of pgrep command.
Example:
#pkill java
We can force the process to terminate by using signal 9:
#pkill -9 -x java
Solaris File System
Understanding the SOLARIS file system is very important,
before we discuss anything further. Its huge topic and I
suggest you really need to be patient while going through it.
If you find anything difficult to understand, you can comment
and I will get back to you as soon as possible.
File is the basic unit in Solaris, similar to atom for an
element in chemistry. For example commands are executable
files, documents are text file or file having code/script,
directories are special files containing other files etc.
Blocks: A file occupies the space on disks in units. These
units are called Blocks. The blocks are measured in two sizes
:
1. Physical Block size: Its the size of the smallest block
that the disk controller can read or write. The physical block
size is usually 512B for UFS(Unix Files System). It may vary
from file system to file system.
2. Logical Block size: Its the size of the block that UNIX
73 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
uses to read or write files. It is set by default to the page
size of the system, which is 8KB for UFS.
Inodes: It is a data structure that contains all the file
related information except the file name and data. It is 128
kb in size and is stored in cylindrical information block. The
inode contains following information about a file :
1. Type of File : e.g. regular file, block special, character
special, directory, symbolic link, other inode etc.
2. The file modes : e.g. read, write, execute permissions.
3. The number of hard links to the file.
4. The group id to which the file belongs
5. The user ID that owns the file.
6. The number of bytes in the file.
7. An array of addresses for 15 disk blocks
8. The date and time when the file was created, last accessed
and last modified.
So, an Inode contains almost all the information about a file.
But what is more important is what an inode does not contain.
An inode does not contain the "file name" and data. The file
name is stored inside a directory and data is saved in blocks
There is an inode associated with each file. So, the number of
inodes determines the maximum number of files in the files
system. The number of inodes depends upon the size of file
system. For example : lets take a file system of size 2gb. The
inode size will be 4kb each. So the number of inodes = 2gb
/4kb = 524288. So the maximum number of files that can be
created is 524288.
File system: Its the way an operating system organizes files
on a medium(storage device).
74 AshisChandraDas
Infrastructure Sr.Analyst # Accenture >
The different flavors of UNIX have different default file
systems. Few of them are listed below:
SOLARIS - UFS (Unix File System)
AIX - JFS (journal FS)
JP - HFS (high performance FS)
LINUX - ext2 & ext3
Before getting into the UFS file system, lets discuss about
the architecture of the file system in SOLARIS and other file
systems used in SOLARIS.
SOLARIS uses VFS (Virtual File System architecture). It
provides standard interface for different file system types.
The VFS architecture enables kernel to perform basic file
operation such as reading, writting and listing. Its is
called virtual because the user can issue same command to work
regardless of the file system. SOLARIS also uses memory based
file system and disk based file system.
Lets discuss some memory based file systems:
Memory based File Systems:
It use the physical memory rather than disk and hence also
called Virtual File System or pseudo file system. Following
are the Memory based file system supported by SOLARIS:
1. Cache File System(CacheFS): It uses the local disk to cache
the data from the slow file systems like CD - ROM.
2. Loopback File System(LOFS): If we want to make a file
system e.g: /example to look like /ex, we can do that by
creating a new virtual file system known as Loopback File
System.
3. Process File System(PROOFS): It is used to contains the
list of active process in SOLARISby their process ID, in the
/proc directory. It is used by the ps command.
4. Temporary File System(TEMPFS): It is the temporary file
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris
sun solaris

More Related Content

Similar to sun solaris

How To Manage Linux User on RHEL 7
How To Manage Linux User on RHEL 7How To Manage Linux User on RHEL 7
How To Manage Linux User on RHEL 7VCP Muthukrishna
 
8 passwordsecurity
8 passwordsecurity8 passwordsecurity
8 passwordsecurityricharddxd
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissionsShay Cohen
 
4_Users_and_File_Permission_and_Directory_Commands
4_Users_and_File_Permission_and_Directory_Commands4_Users_and_File_Permission_and_Directory_Commands
4_Users_and_File_Permission_and_Directory_CommandsGautam Raja
 
Useradmin
Useradmin Useradmin
Useradmin ARYA TM
 
Windows command prompt a to z
Windows command prompt a to zWindows command prompt a to z
Windows command prompt a to zSubuh Kurniawan
 
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...Nicolas Desachy
 
UGIF 12 2010 - new security features in IDS - nov 2010
UGIF 12 2010 - new security features in IDS - nov 2010UGIF 12 2010 - new security features in IDS - nov 2010
UGIF 12 2010 - new security features in IDS - nov 2010UGIF
 
Chapter03 Creating And Managing User Accounts
Chapter03      Creating And  Managing  User  AccountsChapter03      Creating And  Managing  User  Accounts
Chapter03 Creating And Managing User AccountsRaja Waseem Akhtar
 
Addmi 06-security mgmt
Addmi 06-security mgmtAddmi 06-security mgmt
Addmi 06-security mgmtodanyboy
 
linux_Commads
linux_Commadslinux_Commads
linux_Commadstastedone
 
Chapter 09
Chapter 09Chapter 09
Chapter 09cclay3
 
Users and groups in Linux
Users and groups in LinuxUsers and groups in Linux
Users and groups in LinuxKnoldus Inc.
 
Windows post exploitation
Windows post exploitationWindows post exploitation
Windows post exploitationyarden hanan
 
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptxUNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptxLeahRachael
 

Similar to sun solaris (20)

How To Manage Linux User on RHEL 7
How To Manage Linux User on RHEL 7How To Manage Linux User on RHEL 7
How To Manage Linux User on RHEL 7
 
7 - User Administration in Red Hat
7 - User Administration in Red Hat7 - User Administration in Red Hat
7 - User Administration in Red Hat
 
8 passwordsecurity
8 passwordsecurity8 passwordsecurity
8 passwordsecurity
 
Ch10 system administration
Ch10 system administration Ch10 system administration
Ch10 system administration
 
Ch10
Ch10Ch10
Ch10
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissions
 
4_Users_and_File_Permission_and_Directory_Commands
4_Users_and_File_Permission_and_Directory_Commands4_Users_and_File_Permission_and_Directory_Commands
4_Users_and_File_Permission_and_Directory_Commands
 
User management
User managementUser management
User management
 
Less07 Users
Less07 UsersLess07 Users
Less07 Users
 
Useradmin
Useradmin Useradmin
Useradmin
 
Windows command prompt a to z
Windows command prompt a to zWindows command prompt a to z
Windows command prompt a to z
 
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...
Informix User Group France - 30/11/2010 - IDS les nouvelles fonctionnalités s...
 
UGIF 12 2010 - new security features in IDS - nov 2010
UGIF 12 2010 - new security features in IDS - nov 2010UGIF 12 2010 - new security features in IDS - nov 2010
UGIF 12 2010 - new security features in IDS - nov 2010
 
Chapter03 Creating And Managing User Accounts
Chapter03      Creating And  Managing  User  AccountsChapter03      Creating And  Managing  User  Accounts
Chapter03 Creating And Managing User Accounts
 
Addmi 06-security mgmt
Addmi 06-security mgmtAddmi 06-security mgmt
Addmi 06-security mgmt
 
linux_Commads
linux_Commadslinux_Commads
linux_Commads
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Users and groups in Linux
Users and groups in LinuxUsers and groups in Linux
Users and groups in Linux
 
Windows post exploitation
Windows post exploitationWindows post exploitation
Windows post exploitation
 
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptxUNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
UNIT 6-EXPLAINING THE ROLE OF THE NETWORK ADMINISTRATOR AND SUPPORT.pptx
 

sun solaris

  • 1. 1 AshisChandraDas Infrastructure Sr.Analyst # Accenture > INDEX Page 1. User Administration 02 2. Networking Advance Concepts : part 1 18 3. Working with Files and Directories 30 4. VI Editor 43 5. Working with Shell 48 6. Process Management 69 7. Drilling Down the File System 90 8. Boot PROM Basics 113 9. Solaris 10 Boot Process & Phases 124 10 .NFS & AutoFS 158 11. SolarisVolume Management
  • 2. 2 AshisChandraDas Infrastructure Sr.Analyst # Accenture > User Administration User Administration: In Solaris each user requires following details: 1. A unique user name 2. A user ID 3. home directory 4. login shell 5. Group to which the user belongs. System files used for storing user account information are: The /etc/passwd file: It contains login information for authorized system user. It displays following seven fields in each entry: loginID A string maximum of 8 chars including numbers & lowercase and uppercase letters. The first character should be a letter. x It is the password place holder which is stored under /etc/shadow file. UID Unique user ID. System reserves the values 0 to 99 for system accounts. The UID 60001 is reserved for the nobody account & 60002 is reserved for the noaccess account. The UID after 60000 should be avoided. GID Group ID. System reserves the values 0 to 99 for system accounts. The GID numbers for users ranges from 100 to 60000. comment Generally contains user full name. home directory Full path for user's home directory. login shell The user's default login shell. It can be anyone from the list : Bourne shell, Korn shell, C shell, Z shell, BASH shell, TC shell. Few default system account entries: User name User ID Description root 0 Root user account which has access to the entire system daemon 1 The system daemon account associated with routine system tasks bin 2 The Administrative daemon account that is
  • 3. 3 AshisChandraDas Infrastructure Sr.Analyst # Accenture > associated with routine system tasks sys 3 The Administrative daemon account that is associated with system logging or updating files in temporary directories. adm 4 The Administrative daemon account that is associated with system logging lp 71 Printer daemon account The /etc/shadow file: It contains encrypted password.The encrypted password is 13 characters long and encrypted with 128 bit DESA encryption. The /etc/shadow file contains following fields: loginID It contains the user's login name password It contains the 13 letter encrypted password lastchg Number of days between 1st January & last password modification date. min Minimum number of days to pass before you can change the password. max Maximum number of days after which a password change is necessary. warn The number of days prior to password expiry that the user is warned. inactive The number of inactive days allowed for the user before the user account is locked. expire The number of days after which the user account would expire. The number of days are counted since 1st Jan 1970. flag It is used to track failed logins. It maintains count in low order. The /etc/group file: It contains default system group entries. This file is used to create/modify the groups.The /etc/shadow file contains following fields: groupname It contains the name assigned to the group. Maximum 8 characters. group- password It is group password and is generally empty due to security reasons. GID Group's GID number. username- list It contains the list of secondary groups with which user is associated. This list is separated by
  • 4. 4 AshisChandraDas Infrastructure Sr.Analyst # Accenture > commas and by default maximum of 15 secondary groups can be associated to each user. The /etc/default/passwd File: It is used to control the properties for all user passwords on the system. The /etc/default/passwd contains following fields: MAXWEEKS It is used to set the maximum time period in weeks for which the password is valid. MINWEEKS It is the minimum time period after which the password can be changed. PASSLENGHT Minimum number of characters for password length. WARNWEEKS It sets the time period prior to password's expiry that the user should be warned. NAMECHECK=NO Sets the password controls to verify that the user is not using the login name as a component of password. HISTORY=0 Forces the passwd program to store the number of old passwords. The maximum number of allowed is 26. DICTIONLIST= Causes the passwd program to perform dictionary word lookups from comma- separated dictionary files. DICTIONBDIR=/var/passwd The location of the dictionary where the generated dictionary database reside. Values in /etc/default/passwd: Password Management: pam_unix_auth module is responsible for the password management in Solaris. To configure locking of user account after specified number of attempts following parameters are modified:
  • 5. 5 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 1. LOCK_AFTER_RETRIES tunable parameter in the /etc/security/policy.conf file & 2. lock_after-retries key in the /etc/user_attr file is modified. Note: The LOCK_AFTER_RETRIES parameter is used to specify the number of failed login attempts after which the user account is locked. The number of attempts are defined by RETRIES parameter in the /etc/default/login file. passwd command: The passwd command is used to set the password for the user account. syntax: #passwd <options> <user name> Various options used with the passwd command are described below: -s Shows password attributes for a particular user. When used with the -a option, attributes for all user accounts are displayed. -d Deletes password for name and unlocks the account. The login name is not prompted for a password. -e Changes the login shell, in the /etc/passwd file, for a user. -f Forces the user to change passwords at the next login by expiring the password. -h Changes the home directory, in the /etc/passwd file, for a user. -l Lock a user's account. Use the -d or -u option to unlock the account. -N Makes the password entry for <name> a value that cannot be used for login but does not lock the account. It is used to create password for non-login account(e.g accounts for running cron jobs). -u Unlocks a locked account. Preventing user from using previously used password: 1. Edit the /etc/default/passwd file and uncomment the line HISTORY=0 2. Set the value of HISTORY=n, where n is the number of passwords to be logged and checked. Managing User Accounts: Adding a user account:
  • 6. 6 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #useradd -u <User ID> -g <Primary Group> -S <secondary group> -d <user home dir> -m -c <user Desc> -s <User login shell> <User Name> The option -m forcibly creates the user home directory if it is not there. Note: The default group id will be 1(group name is system). useradd command options: -c <comment> A short description of the login, typically the user's name and phone extension. This string can be up to 256 characters. -d <directory> Specifies the home directory of the new user. This string is limited to 1,024 characters. -g <group> Specifies the user's primary group membership. -G <group> Specifies the user's secondary group membership. -n <login> Specifies the user's login name. -s <shell> Specifies the user's login shell. -u <uid> Specifies the user ID of the user you want to add. If you do not specify this option, the system assigns the next available unique UID greater than 100. -m SeCreates a new home directory if one does not already exist. Default values for creating a user account: There is a preset range of default values associated with the useradd command. These values can be displayed using -D option. The useradd command with -D option creates a file /use/sadm/defadduser for the first time. The values in /use/sadm/defadduser is used as default values for useradd command. Example: Adding a new user account test.
  • 7. 7 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Note: When a user account is created using useradd command it is locked and need to be unlocked & password is set using passwd command. Modifying a user account: Modifying a user id: # usermod -u <New User ID> <User Name> Modifying a primary group: #usermod -g <New Primary Group> <User Name> Modifying a secondary group: #usermod -G <New Secondary Group> <User Name> In similar manner we can modify other user related information. Deleting a user account: #userdel <user name> → user's home directory is not deleted #userdel -r <user name> → user's home directory is deleted Locking a User Account: # passwd -l <user name> Unlock a User Account: #passwd -u <user name> Note: uid=0 (Super user, administrator having all privileges). By default root is having uid = 0 which can be duplicated. This is the only user id which can be duplicated.
  • 8. 8 AshisChandraDas Infrastructure Sr.Analyst # Accenture > For example: 1. #useradd -u 0 -o <user name> 2. #usermod -u 0 -o <user name> Here option -o is used to duplicate the user id 0. smuser command: This command is used for remote management of user accounts. Example: If you want to add a user raviranjan in nis domain office.com on system MainPC use smuser command as follows: # /usr/sadm/bin/ smuser add -D nis:/MainPC/office.com -- -u 111 -n raviranjan The subcommands used with smuser command: add To add a new user account. modify To modify a user account. delete To delete a user account. list To list one or more user accounts. smuser add options: -c <comment> A short description of the login, typically the user's name and phone extension. This string can be up to 256 characters. -d <directory> Specifies the home directory of the new user. This string is limited to 1,024 characters. -g <group> Specifies the user's primary group membership. -G <group> Specifies the user's secondary group membership. -n <login> Specifies the user's login name. -s <shell> Specifies the user's login shell. -u <uid> Specifies the user ID of the user you want to add. If you do not specify this option, the system assigns the next available unique UID greater than 100. -x autohome=Y|N Sets the home directory to automount if set to Y. smgroup command: This command is used for remote management of groups. Example: If you want to add a group admin in nis domain office.com on system MainPC use smgroup command as follows: #/usr/sadm/bin/smgroup add -D nis:/MainPC/office.com -- -g 101 -n admin The subcommands used with smgroup command: add To add a new group.
  • 9. 9 AshisChandraDas Infrastructure Sr.Analyst # Accenture > modify To modify a group. delete To delete a group. list To list one or more group. Note: The use of subcommands requires authorization with the Solaris Management Console server. Solaris Management Console also need to be initialized. Managing Groups: There are two groups related to a user account: 1. Primary Group: The maximum and minimum number of primary group for a user is 1. 2. Secondary Group: A user can be member of maximum 15 secondary groups. Adding a group #groupadd <groupname> #groupadd -g <groupid> <groupname> The group id is updated under /etc/group. #vi /etc/group ss2::645 Note: Here ss2 is group name and 645 is group id. Modifying a group By group ID: #groupmod -g <New Group ID> <Old Group Name> By group Name: #groupmod -n <New Group Name> <Old Group Name> Note: For every group we are having a group name and id(for kernel reference). By default 0-99 group ids are system defined. The complete information about the group is stored under /etc/group file. Deleting a group # groupdel <group name> Variables for customizing a user session: Variable Set By Description LOGNAME login Defines the user login name HOME login used to set path of user's home directory and is the default argument of the cd command SHELL login Contains path to the default shell
  • 10. 10 AshisChandraDas Infrastructure Sr.Analyst # Accenture > PATH login Sets the default path where the command is searched MAIL login Sets path to the mailbox of the user TERM login Used to define the terminal PWD shell Defines the current working directory PS1 shell Defines shell prompt for bourne or korn shell prompt shell Contains the shell prompt for C shell Setting login variables for the shell: Shell User's Initialization file Bourne/Korn VARIABLE=value;export VARIBLE eg:#PS1="$HOSTNAME";export PS1 C setenv variable value Monitoring System Access: who command : This command displays the list of users currently logged in to the system. It contains user's login name, device(eg. console or terminal), login date & time and the remote host IP address. ruser command: This command displays the list of users logged in to the local and remote host. The output is similar to the who command. Finger Command: By default, the finger command displays in multi-column format the following information about each logged-in user: user name user's full name terminal name(prepended with a '*' (asterisk) if write- permission is denied) idle time login time host name, if logged in remotely Syntax: finger [ -bfhilmpqsw ] [ username... ] finger [-l ] [ username@hostname1[@hostname2...@hostnamen] ... ] finger [-l ] [ @hostname1[@hostname2...@hostnamen] ... ] Options: -b Suppress printing the user's home directory and shell in a long format printout.
  • 11. 11 AshisChandraDas Infrastructure Sr.Analyst # Accenture > -f Suppress printing the header that is normally printed in a non-long format printout. -h Suppress printing of the .project file in a long format printout. -i Force "idle" output format,which is similarto short format except that only the login name,terminal,login time,and idle time are printed. -l Force long output format. -m Match arguments only on user name (not first or last name). -p Suppress printing of the .plan file in a long format printout. -q Force quick output format, which is similar to short format except that only the login name, terminal, and login time are printed. -s Force short output format. -w Suppress printing the full name in a short format printout. Note: The username@hostname form supports only the -l option. last command: The output of this command is very long and contains information about all the users. We can user the last command in following ways: 1. To display the n lines from the o/p of last command: #last -n 10 2. Login information specific to a user: #last <user name> 3. last n reboot activities: #last -10 reboot
  • 12. 12 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Recording failed login attempts: 1. Create a file /var/adm/loginlog. #touch /var/adm/loginlog 2. Root user should be the owner of this file and it should belog to group sys. #chown root:sys /var/adm/loginlog 3. Assign read and write permission for the root user. #chmod 600 /var/adm/loginlog This will log all failed login attempts after five consecutive failed attempts. This can be changed by modifying the RETRIES entry in /etc/default/login. The loginlog file contains: user's login name user's login device time of the failed attempt su command: The su (substitute user) command enables to change a login session's owner without the owner having to first log out of that session. Syntax: #su [options] [commands] [-] [username] Examples: #su The operating system assumes that, in the absence of a username, the user wants to change to a root session, and thus the user is prompted for the root password as soon as the
  • 13. 13 AshisChandraDas Infrastructure Sr.Analyst # Accenture > ENTER key is pressed. This produces the same result as typing: #su root To transfer the ownership of a session to any other user, the name of that user is typed after su and a space. #su ravi The user will then be prompted for the password of the account with the username ravi. The '-' option with su command: 1. Executes the shell initialization files of the switched user. 2. Modifies the work environment to change it to the work environment of the specified user. 3. Changes the user's home directory. The whoami command: This command displays the name of the currently logged in user. Example: #su ravi $whoami ravi $ The 'who am i' command: This displays the login name of the original user. Example: #whoami root #su ravi $who am i root $ Monitoring su attempts: You can monitor su attempts by monitoring the /var/adm/sulog file. This file logs each time the su command is used. The su logging in this file is enabled by default through the following entry in the /etc/default/su file: SULOG=/var/adm/sulog The sulog file lists all uses of the su command, not only the su attempts that are used to switch from user to superuser. The entries show the date and time the command was entered, whether or not the attempt was successful (+ or -), the port from which the command was issued, and finally, the name of the user and the switched identity.
  • 14. 14 AshisChandraDas Infrastructure Sr.Analyst # Accenture > The console parameter in /etc/default/su file contains the device name to which all atempts to switch user should be logged CONSOLE=/dev/console By default this option is commented. Controlling system Access: 1. /etc/default/login: CONSOLE Variable: This parameter can be used to restrict the root user login. The value /dev/console for CONSOLE variable enables the root user to login from system console only. The remote login for root is user is not possible. However, if the parameter CONSOLE is commented or not defined, the root user can login to the device from any other system on the networ. PASSREQ: If set to YES, forces user to enter the password when they login for first time. This is applicable for the user account with no password. 2. /etc/default/passwd: It is centralized password aging file for all this normal users. If we update any information to this file, automatically all users will be updated. 3. /etc/nologin: It is the file which is responsible for restricting all the normal users not to access server. By default this file does not exists. To restrict all normal users from login: #touch /etc/nologin #vi /etc/nologin Server is under maintenance. Please try after 6:00PM. :wq! 4./etc/skel: It is the directory which contains all the users environmental files information. When we are creating the user with useradd command along with -m attributes it starts copying all the environmental files from /etc/skel to user’s home directory. 5. /etc/security/policy.conf To lock the user after repeated failed logins#vi /etc/security/policy.conf (go to last line) LOCK_FAILED_LOGINS = NO (Change it to YES) 6. /var/adm/lastlog 7. /var/adm/wtmp
  • 15. 15 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 8. /etc/ntmp Note: The following file systems are the binary files responsible for recording last users login & log out information: 1. /var/adm/lastlog 2. /var/adm/wtmp 3. /etc/ntmp 9. /etc/ftpd/ftpuser: This contains the list of user not allowed to access the system using the ftp protocol. chown command:Use the chown command to change file ownership. Only the owner of the file or superuser can change the ownership of a file. Syntax: #chown -option <user name>|<user ID> <file name> You can change ownership on groups of files or on all of the files in a directory by using metacharacters such as * and ? in place of file names or in combination with them. You can change ownership recursively by use the chown -R option. When you use the -R option, the chown command descends through the directory and any sub directories setting the ownership ID. If a symbolic link is encountered, the ownership is changed only on the target file itself. chgrp command: This command is used to change the ownership of the group owner of the file or directory. Syntax: #chgrp <group name>|<group ID> <file names> setuid Permission: When setuid (set-user identification) permission is set on an executable file, a process that runs this file is granted access based on the owner of the file (usually root), rather than the user who created the process. This permission enables a user to access files and directories that are normally available only to the owner. The setuid permission is shown as an s in the file permissions. For example, the setuid permission on the passwd command enables a user to change passwords, assuming the permissions of the root ID are the following: # ls -l /usr/bin/passwd -r-sr-sr-x 3 root sys 96796 Jul 15 21:23 /usr/bin/passwd
  • 16. 16 AshisChandraDas Infrastructure Sr.Analyst # Accenture > NOTE: Using setuid permissions with the reserved UIDs (0-99) from a program may not set the effective UID correctly. Instead, use a shell script to avoid using the reserved UIDs with setuid permissions. You setuid permissions by using the chmod command to assign the octal value 4 as the first number in a series of four octal values. Use the following steps to setuid permissions: 1. If you are not the owner of the file or directory, become superuser. 2. Type chmod <4nnn> <filename> and press Return. 3. Type ls -l <filename> and press Return to verify that the permissions of the file have changed. The following example sets setuid permission on the myprog file: #chmod 4555 myfile -r-sr-xr-x 1 ravi admin 12796 Jul 15 21:23 myfile # setgid Permission The setgid (set-group identification) permission is similar to setuid, except that the effective group ID for the process is changed to the group owner of the file and a user is granted access based on permissions granted to that group. The /usr/bin/mail program has setgid permissions: # ls -l /usr/bin/mail -r-x—s—x 1 bin mail 64376 Jul 15 21:27 /usr/bin/mail # When setgid permission is applied to a directory, files subsequently created in the directory belong to the group the directory belongs to, not to the group the creating process belongs to. Any user who has write permission in the directory can create a file there; however, the file does not belong to the group of the user, but instead belongs to the group of the directory. You can set setgid permissions by using the chmod command to assign the octal value 2 as the first number in a series of four octal values. Use the following steps to set setgid permissions: 1. If you are not the owner of the file or directory, become superuser.
  • 17. 17 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 2. Type chmod <2nnn> <filename> and press Return. 3. Type ls -l <filename> and press Return to verify that the permissions of the file have changed. The following example sets setuid permission on the myfile: #chmod 2551 myfile #ls -l myfile -r-xr-s—x 1 ravi admin 26876 Jul 15 21:23 myfile # Sticky Bit The sticky bit on a directory is a permission bit that protects files within that directory. If the directory has the sticky bit set, only the owner of the file, the owner of the directory, or root can delete the file. The sticky bit prevents a user from deleting other users' files from public directories, such as uucppublic: # ls -l /var/spool/uucppublic drwxrwxrwt 2 uucp uucp 512 Sep 10 18:06 uucppublic When you set up a public directory on a TMPFS temporary file system, make sure that you set the sticky bit manually. You can set sticky bit permissions by using the chmod command to assign the octal value 1 as the first number in a series of four octal values. Use the following steps to set the sticky bit on a directory: 1. If you are not the owner of the file or directory, become superuser. 2. Type chmod <1nnn> <filename> and press Return. 3. Type ls -l <filename> and press Return to verify that the permissions of the file have changed. The following example sets the sticky bit permission on the pubdir directory: # chmod 1777 pubdir # ls -l pubdir drwxrwxrwt 2 winsor staff 512 Jul 15 21:23 pubdir
  • 18. 18 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Viewing & monitoring Network Interfaces: Following are the three important commands used for viewing & monitoring network interfaces: 1. ifconfig: This command shows OSI layer 2 related information. To display all the status of all interfaces use following command: # ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 The above command shows that the interface lo0 is up with IP address 127.0.0.1 ifconfig can be used to up or down the interface: #ifconfig lo0 down #ifconfig lo0 up 2. ping: This command is used to communicate with another system over the network. The ping uses ICMP protocol to communicate. #ping computer1 computer1 is alive #ping computer2 no answer In the above example the computer1 is reachable but computer2 is not reachable. 3. snoop: It is used to capture and inspect network packets to determine the kind of data transferred between systems. #snoop system1 system2 system1 -> system2 ICMP Echo request (ID:710 Sequence number:0) system2 -> system1 ICMP Echo reply (ID:710 Sequence number:0) The above command is used to intercept the communication between system1 & system2. The system1 is trying to ping system2 and the ping is success. snoop -o <file name>: Saves captured packets in file name as they are captured snoop -i <file name>: Displays packets previously captured in
  • 19. 19 AshisChandraDas Infrastructure Sr.Analyst # Accenture > file name snoop -d <device>: Receives packets from a network interface specified by device The Network Interfaces in Solaris is controlled by files & services: svcs:/network/physical:default Service This service calls /lib/svcs/method/net-physical method script. This script is run every time the system is rebooted. This script uses ifconfig utility to configure each interface. It searches for file /etc/hostname.xxn. For each /etc/hostname.xxn file, the script uses ifconfig command with the plumb option to make kernel ready to communicate to the interface. The script then configures the names interfaces by using other options of the ifconfig command. Note: In Solaris 8 & 9, the /etc/rcS.d/S30network.sh file is used to perform the same function. Before Solaris 8 OS, the /etc/rcS.d/S30rootusr.sh fiel was used. /etc/hostname.xxn files These file contains an entry that configures a corresponding interface. The variable component (xx) is replaced by an interface type and a number that differentiates between multiple interface of the same type configured in the system.The following table shows an example of file entries for Ethernet interfaces commonly found in Solaris systems: /etc/hostname.e1000g0 First e1000g (Intel PRO/1000 Gigabit family device driver) Ethernet interface in the system /etc/hostname.bge0 First bge (Broadcom Gigabit Ethernet device driver) Ethernet interface in the system /etc/hostname.bge1 Second bge Ethernet interface in the system /etc/hostname.ce0 First ce (Cassini Gigabit Ethernet Device driver) Ethernet interface in the system /etc/hostname.qfe0 First qfe(Quad Fast-Ethernet Device driver) Ethernet interface in the system /etc/hostname.hme0 First hme (Fast-Ethernet Device driver) Ethernet interface in the system /etc/hostname.eri0 First eri (eri Fast-Ethernet Device driver) Ethernet interface in the system /etc/hostname.nge0 First nge (Nvidia Gigabit Ethernet Device driver) Ethernet interface in the system
  • 20. 20 AshisChandraDas Infrastructure Sr.Analyst # Accenture > The /etc/hostname.xxn files contain either the host name or the IP address of the system that contains the xxn interface. The host name must be there in the file /etc/inet/hosts file so that it can be resolved to an IP address at system boot. Example: # cat /etc/hostname.ce0 Computer1 netmask + broadcast + up /etc/inet/hosts file: It is the file which associates the IP addresses of hosts with their names.It can be used with, or instead of , other hosts databases including DNS, NIS hosts map & NIS+ hosts table. The /etc/inet/hosts file contains at least the loopback & host information. It has one entry for each IP address of each host. The entries in the files are in following format: <IP address> <Host name> [aliases] 127.0.0.1 localhost /etc/inet/ipnodes file: It is a local database or file that associates the names of nodes with their IP addresses. It is a symbolic link to the /etc/inet/hosts file. It associates the names of nodes with their Internet Protocol (IP) addresses. The ipnodes file can be used in conjuction with, instead of, other ipnodes databases, including the DNS, the NIS ipnodes map, and LDAP. The fomat of each line is: <IP address> <Host Name> [alias] # internet host table ::1 localhost 127:0:0:1 localhost 10.21.108.254 system1 Changing the System Host Name: The system host name is in four system files & we must modify these files and perform a reboot to change a system host name: /etc/nodename /etc/hostname.xxn /etc/inet/hosts /etc/inet/ipnodes sys-unconfig Command: The /usr/sbin/sys-unconfig command is used to restore a system configuration to an unconfigured state. This command does the following: 1. It saves the current /etc/inet/hosts files information in the /etc/inet/hosts.saved file. 2. It saves the /etc/vfstab files to the /etc/vfstab.orig file if the current /etc/vfstab file contains NFS mount entries. 3. It restores the default /etc/inet/hosts file.
  • 21. 21 AshisChandraDas Infrastructure Sr.Analyst # Accenture > NETSTAT: It lists the connection for all protocols and address family to and from machine. The address family (AF) includes: INET – ipv4 INET - ipv6 UNIX – Unix Domain Sockets(Solaris/FreeBSD/Linux etc.) Protocols supported in INET/INET6 are: TCP, IP, ICMP(PING), IGMP, RAWIP, UDP(DHCP, TFTP) NETSTAT also list: 1. routing tables, 2. any multi-cast entry for NIC, 3 .DHCP status for various interfaces, 4.net-to-media/MAC table. Usage: # netstat UDP: Ipv4 Local Address Remote Address State -------------------- -------------------- ---------- System1.bge0.54844 10.95.8.202.domain Connected System1.bge0.54845 10.95.8.213.domain Connected TCP: Ipv4 Local Address Remote Address Swind Send-Q Rwind Recv-Q State -------------------- -------------------- ----- ------ ----- - ----- ----------- localhost.41771 localhost.3306 49152 0 49152 0 ESTABLISHED localhost.3306 localhost.41771 49152 0 49152 0 ESTABLISHED localhost.50230 localhost.3306 49152 0 49152 0 CLOSE_WAIT localhost.50231 localhost.3306 49152 0 49152 0 CLOSE_WAIT Note: NETSTAT returns sockets by protocol using /etc/services lookup. Below example gives detailed information about the /etc/services files. # ls -ltr /etc/services lrwxrwxrwx 1 root root 15 Apr 8 2009 /etc/services -> ./inet/services(its soft link to /etc/inet/services) The below example shows the content of the /etc/services file. Its columns represents Network services, port number and Protocol. # less /etc/services # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. #
  • 22. 22 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #ident "@(#)services 1.34 08/11/19 SMI" # # Network services, Internet style # tcpmux 1/tcp echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users daytime 13/tcp daytime 13/udp netstat 15/tcp Note: The NETSTAT command resolves the host name with the help of local /etc/hosts file or DNS server. There is an important file /etc/resolv.conf which tells resolver what look up facilities such as LDAP, DNS or files to use. /etc/nssswitch.conf is consulted by netstat to resolve names for IP. /etc/resolv.conf: # cat /etc/resolv.conf domain WorkDomain nameserver 10.95.8.202 nameserver 10.95.8.213 /etc/hosts file: # cat /etc/hosts 127.0.0.1 localhost 172.30.228.58 mysystem.bge0 bge0 172.30.228.58 mysystem loghost The command netstat -a will dump the connection including name lookup from /etc/services directly. It returns all protocols for all address families (TCP/UDP/UNIX). #netstat -a UDP: Ipv4 Local Address Remote Address State -------------------- -------------------- ---------- *.snmpd Idle *.55466 Idle System1.bge0.55381 10.95.8.202.domain Connected System1-prod.bge0.55382 10.95.8.213.domain Connected *.32859 Idle #netstat -an : -n option disables the name resolution of hosts and ports and speed up the o/p time
  • 23. 23 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #netstat -i: returns state of configured interfaces. # netstat -i Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue lo0 8232 loopback localhost 1498672734 0 1498672734 0 0 0 nge0 1500 System1.bge0 System1.bge0 1081897064 0 1114394170 6 0 0 #netstat -m : It returns streams(TCP) statistics streams allocation: cumulative allocation current maximum total failures streams 408 4350 28881897 0 queues 841 4764 43912097 0 mblk 7062 40068 780613980 0 dblk 7062 45999 4815973363 0 linkblk 5 84 6 0 syncq 17 75 58511 0 qband 0 0 0 0 2469 Kbytes allocated for streams data #netstat -p : It returns net to media information(MAC/layer-2 information). Net to Media Table: Ipv4 Device IP Address Mask Flags Phys Addr ------ -------------------- --------------- -------- --------- ------ nge0 defaultrouter 255.255.255.255 00:50:5a:1e:e4:01 nge0 172.30.228.54 255.255.255.255 00:14:4f:6f:39:13 nge0 172.30.228.52 255.255.255.255 o 00:14:4f:7e:97:53 nge0 172.30.228.53 255.255.255.255 o 00:14:4f:6f:4f:75 nge0 172.30.228.49 255.255.255.255 00:1e:68:86:84:16 nge0 System1.bge0 255.255.255.255 SPLA 00:21:28:70:19:36 nge0 System2 255.255.255.255 o 00:21:28:6b:c6:7a nge0 172.30.228.57 255.255.255.255 SPLA 00:21:28:70:19:36 nge0 224.0.0.0 240.0.0.0 SM 01:00:5e:00:00:00 #netstat -P <protocol> (ip|ipv6|icmp|icmpv6|tcp|udp|rawip|raw|igmp): returns active sockets for selected protocol. #netstat -r : returns routing table # netstat -r Routing Table: Ipv4 Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- -------- -- --------- default defaultrouter UG 1 53637 172.30.228.0 System1.bge0 U 1 3295 nge0 172.30.228.0 172.30.228.57 U 1 0 nge0:1 224.0.0.0 System1.bge0 U 1 0 nge0
  • 24. 24 AshisChandraDas Infrastructure Sr.Analyst # Accenture > localhost localhost UH 201 15889818 lo0 #netstat -D : It returns DHCP Configuration information (lease duration/renewal etc.) #netstat -a -f <address_family>: It returns result corresponding to the specified address family netstat -a -f inet|inet6|unix netstat -a -f inet : It returns ipv4 information only. Network Configuration There are two main configuration: 1. Local files : configuration is defined statically via key files 2. Network configuration : DHCP is used to auto-config interfaces dladm command: It is used to determine the physical interfaces using following command: dladm show-dev or show-link. The another command to check the same is ifconfig -a. However there is a difference between O/Ps. The dladm shows layer 1 related information whereas ifconfig command returns layer 2&3 related information. # dladm show-dev ce0 link: unknown speed: 1000 Mbps duplex: full ce1 link: unknown speed: 1000 Mbps duplex: full ge0 link: unknown speed: 1000 Mbps duplex: unknown eri0 link: unknown speed: 100 Mbps duplex: full # ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 ce0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6 inet 10.22.213.80 netmask ffffff00 broadcast 10.22.213.255 ether 0:14:4f:67:90:c1 ce1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu
  • 25. 25 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 1500 index 3 inet 10.22.217.35 netmask ffffff00 broadcast 10.22.217.255 ether 0:14:4f:44:4:50 eri0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4 inet 10.22.224.147 netmask ffffff00 broadcast 10.22.224.255 ether 0:14:4f:47:92:5e ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5 inet 10.22.240.108 netmask ffffff00 broadcast 10.22.240.255 ether 0:14:4f:47:92:5f Key network configuration files:svcs -a | grep physical : This command can be used to see the service responsible for running/starting the physical interfaces. svcs -a | grep loopback: This command can be used to see the service responsible for running/starting the local loopback interface. Configuring Network 1. IP Address( /etc/hostname.interface): We need to configure /etc/hostname.interface(e.g /etc/hostname.e1000g0, /etc/hostname.iprb01) for each physical and virtual interface listed by the dladm command. The IP address must be listed in this file. However this is not a requirement in DHCP or network configuration mode. 2. Domain name( /etc/defaultdomain): We need to configure /etc/defaultdomain. This is not a requirement in case of DHCP mode of network configuration. This contains domain name information for the host. 3.Netmask(/etc/inet/netmasks): We need to create a files /etc/inet/netmasks if not there. This is also managed by DHCP. The netmasks file associates Internet Protocol (IP) address masks with IP network numbers. network-number netmask The term network-number refers to a number obtained from the Internet Network Information Center. Both the network-number and the netmasks are specified in "decimal dot" notation, e.g: 128.32.0.0 255.255.255.0 4. Hosts database(/etc/hosts): It is symbolically linked with /etc/inet/hosts, contains the entry for the loopback adapter and for each IP address linked with the network adapter for name resolution. It gets auto configured by DHCP.
  • 26. 26 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 5. Client DNS resolver file(/etc/resolv.conf): It reveals dns resolver related information. It gets auto configured by DHCP. 6. Default gateway(/etc/defaultrouter): It is required for communicating with outside network. It is also managed by DHCP under network configuration mode. 7. Node name(/etc/nodename): This file contains the host name and is not mandatory as the host name is resolved by the /etc/hosts file. This is taken care by DHCP in network configuration. Name service configuration file(/etc/nsswitch.conf): It will reveal resolution of various objects. For manually configuring the network from DCP to local files(static) mode, the above mentioned files need to be configured as stated. Once that is done, move/rename/delete the file dhcp.<interfacename>, so that the DHCP agent is not invoked. Plumb/enable the iprb0 100mbps interface(Plumbing interfaces is analogous to enable interfaces): 1. ifconfig iprb0 plumb up → This will enable iprb0 interface. 2. ifconfig iprb0 172.16.20.10 netmask 255.255.255.0 → This will enable layer 3 Ipv4 address. 3. Ensure that the newly plumbed persists across reboot: 1. Creating a file /etc/hostname.interface: echo “172.16.20.10” > /etc/hostname.<interfacename> 2. Create an entry in /etc/hosts file: echo “172.16.20.10 NewHostName” >> /etc/hosts 3. Create an entry in file /etc/inet/netmasks echo “172.16.20.0 255.255.255.0” >> /etc/inet/netmasks Unplumb(disable) an interface: ifconfig <interface name> unplumb down Making an interface to go down without unplumb : ifconfig <interfacename> down Removing an interface: ifconfig <interfacename> removeif <IP Address of interface> Note: If you want the interface to be managed DHCP, create a file dhcp.<interfacename> under /etc directory. Logical(Sub-interfaces) Network Interfaces:For each physical interface many logical interfaces can be created connected to a switch port. This means adding additional IP address to a physical interface. 1. Use ‘ifconfig <interfacename> addif <ip address> <net
  • 27. 27 AshisChandraDas Infrastructure Sr.Analyst # Accenture > mask>’: ifconfig e100g0 addif 192.168.1.51 (RFC-1918 – defaults /24) This will automatically create e100g0:1 logical interface. 2.Making the interface to go up: ifconfig e100g0:1 up Note: 1. This will automatically create an e100g0:1 logical interface. 2. Solaris places new logical interface in down mode by default. 3. Logical/sub-interface are contingent upon physical interface. It means if the physical interface is down the logical interface will also be down. 4. Connections are sourced using the IP address of the physical interface. Save logical/sub-interface for persistent across reboots: 1. Create file /etc/hostname.<interfacename> and make interface IP address as entry to it. 2. Optionally update/etc/hosts file. 3. Optionally update /etc/inet/netmasks file – when subnetting. NSSWITCH.CONF(/etc/nsswitch.conf)It saves primarily name service configuration information. It functions as a policy/rules file for various resolution namely: DNS, passwd(/etc/passwd, /etc/shadow), group(/etc/group), protocols(/etc/inet/protocols), ethers or mac-to-IP mappings, where to look for host resolution. The figure below shows a sample nsswitch.conf file. In the above nsswitch.conf file, the password and group informational resolution is set to files which means the system check for the local files like /etc/shadow, /etc/passwd. For host name resolution which is set to files, first hosts file(/etc/hosts) is checked and if it fails then it is send to appropriate DNS server. NTP(Network Time Protocol): It synchronizes the local system and can be configured to synchronize any NTP aware host. Its hierarchical in design and supports from 1 to 16
  • 28. 28 AshisChandraDas Infrastructure Sr.Analyst # Accenture > strata(precision). Stratum 1 servers are connected to external, more accurate time sources such as GPS. Less latency results in more accurate time. NTP Client configuration: xntpd or ntp service searches for /etc/inet/ntp.conf for configuration file. 1. Copy ntp.client file as ntp.conf file: cp ntp.client ntp.conf 2. Edit ntp.conf and make an entry for the NTP server : server 192.168.1.100 3. Enable ntp service: svcadm enable ntp 4.execute “date” command to check synchronization. The synchronization can be done usingntpdate command as: ntpdate <ServerName> The command “ntpq -p <ServerName>”: This will query the remote system time table. If we just give the command without mentioning the server name, it will list the peers or server for time sync. If we just run the “ntpq “ command, it will run in interactive mode and if we type “help” in that mode it will list various options that can be performed. The command “ntptrace”: Traces path to the time source. If we run it without any option it will default to local system. The command “ntptrace <ServerName>” gives the path and stratum details from the server mentioned to the local system. NTP Server configuration: 1. We need to find the NTP pool site such as: http://www.ntp.org/ . We will derive NTP public server from their lists. 2. Once the list is derived, we need to make the entry of that
  • 29. 29 AshisChandraDas Infrastructure Sr.Analyst # Accenture > list in the file /etc/inet/ntp.conf as shown below:server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 3.asia.pool.ntp.org3. Restart the NTP service: svcadm restart ntp. 4. Making out NTP client machine as NTP server: 1. Go to /etc/inet: cd /etc/inet 2. Disable the NTP service: svcadm disable ntp 3. Copy the file ntp.server to ntp.conf: cp ntp.server ntp.conf 4. Edit ntp.conf file: Make an entry into the file with the servers list obtained from the NTP pool site and local server. 5. Comment the crontab entry for the ntpdate command. 1. crontab -e 2. Comment the line where ntpdate command is run. 6. Enable the NTP service: svcadm enable ntp
  • 30. 30 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Working with Files and Directories Working with Files and Directories is very basic thing which we dont want to miss while learning Solaris 10. Lets check few very basic commands. To display the current working directory: pwd command: It displays the current working directory. example: #pwd /export/home/ravi To display contents of a directory: ls command (Listing Command):It displays all files and directories under the specified directory. Syntax: ls -options <DirName>|<FileName> The options are discussed as follows: Option Description p It lists all the files & directories. The directory names are succeeded by the symbol '/' F It lists all files along with their type. The symbols '/', '*', (None), '@' at the end of file name represents directory, executable, Plain text or ASCII file & symbolic link respectively a It lists all the files & directories name including hidden files l It lists detailed information about files & directories t It displays all the files & directories in descending order of their modified time. r It displays all the files & directories in reverse alphabetical order R It displays all the files & directories & sub-directories in recursive order i It displays the inode number of files & directories tr It displays all the files & directories in the ascending order of their last modified date Analysis of output of ls -l command: ls -l → It list all the files and directories long list with
  • 31. 31 AshisChandraDas Infrastructure Sr.Analyst # Accenture > the permission and other information. The output looks as follows: FileType & Permissions LinkCount UID GID Size Last ModifiedDate & ModifiedTime <File/Directory Name> Following table explains the output: Entry Description FileType '-' for file & 'd' for directory Permissions Permissions are in order of Owner, Group & Other LinkCount Number of links to the file UID Owner's User ID GID Group's ID Size Size of the file/directory Last ModifiedDate & ModifiedTime Last Modified Date & Time of the file/directory <File/Directory Name> File/Directory name Example: # ls -l total 6 -rw-r--r-- 1 root root 136 May 6 2010 local.cshrc -rw-r--r-- 1 root root 167 May 6 2010 local.login -rw-r--r-- 1 root root 184 May 6 2010 local.profile Understanding permissions: Following table explains the permission entry: Entry Description - No permission/denied r read permission w write permission x execute permission
  • 32. 32 AshisChandraDas Infrastructure Sr.Analyst # Accenture > File Command: It is used to determine the file type. The output of file command can be "text", "data" or "binary". Syntax: file <file name> Example: # file data data: English text Changing Directories: 'cd' commad is used to change directories.Syntax: cd <dir name> If cd command is used without any option it changes the directory from current working directory to user's home directory. Example: Let the user be 'ravi' and current working directory is /var/adm/messages #pwd /var/adm/messages #cd #pwd #/export/home/ravi There is also a different way to navigate to the user's home directory : #pwd /var/adm/messages #cd ~ravi #pwd /export/home/ravi #cd ~raju #pwd /export/home/raju #cd ~ravi/dir1
  • 33. 33 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #pwd /export/home/ravi/dir1 In the above examples, the '~' character is the abbreviation that represents the absolute path of the user's home directory. However this functionality is not available in all shells. There are few other path name abbreviations which we can use as well. These are listed below : . → current working directory .. → Parent directory or directory above the current working directory. So if we want to go to the parent directory of the current working directory following command is used: #cd .. We can also navigate multiple levels up in directory using cd, .. and /. Example: If you want to move two levels up the current working directory, we will use the command : #cd ../.. #pwd /export/home/ravi #cd ../.. #pwd /export #cd .. #pwd / Viewing the files: cat command: It displays the entire content of the file
  • 34. 34 AshisChandraDas Infrastructure Sr.Analyst # Accenture > without pausing. Syntax: cat <file name> Example: #file data data: English text #cat data This is an example for demonstrating the cat command. # Warning: The cat command should not be used to open a binary file as it will freeze the terminal window and it has to be closed. So check the file type using 'file' command, if you are not sure about it. more command: It is used to view the content of a long text file in the manner of one screen at a time. Syntax: more <file name> The few scrolling options used with more command are as follows : Scrolling Keys Action Space Bar Moves forward one screen Return Scrolls one line at a time b Moves back one screen h Displays a help menu of features /string searches forward for a pattern n finds the next occurrence of the pattern q quits and returns to shell prompt head command: It displays the first 10 lines of a file by default. The number of lines to be displayed can be changed using the option -n. The syntax for the head command is as follows: Syntax: head -n <file name>
  • 35. 35 AshisChandraDas Infrastructure Sr.Analyst # Accenture > This displays the first n lines of the file. tail command: It displays the last 10 lines of a file by default. The number of lines to be displayed can be changed using the options -n or +n. Syntax: #tail -n <file name> #tail +n <file name> The -n option displays the n lines from the end of the file. The +n option displays the file from line n to the end of the file. Displaying line, word and character count: wc command: It is used to display the number of lines, words and characters in a given file. Syntax: wc -options <file name> The following option can be used with wc command: Option Description l Counts number of lines w Counts number of words m Counts number of characters c Counts number of bytes Example: #cat data This is an example for demonstrating the cat command. #wc -w data 9 Copying Files: cp command: It can be used to copy file/files. Syntax:cp -option(s) surce(s) destination The options for the cp command are discussed below :
  • 36. 36 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Option Description i Prevents the accidental overwriting of existing files or directories r Includes the contents of a directory, including the contents of all sub-directories, when you copy a directory Example: #cp file1 file2 dir1 In the above example file1 and file2 are copies to dir1. Moving & renaming files and directories: mv command: It can be used to 1. Move files and directories within the directory hierarchy : Example: We want to move file1 and file2 under the directory /export/home/ravi to /var #pwd /export/home/ravi #mv file1 file2 /var 2. Rename existing files and directories. Example: we want to rename file1 under /export/home/ravi to file2. #pwd /export/home/ravi #mv file1 file2 The mv command does not affect the contents of the files or directories being moved or renamed. We can use -i option with the mv command to prevent the accidental overwriting of the file. Creating files and directories : touch Command : It is used to create an empty file. We can create multiple file using this command. Syntax: touch <files name> Example: #touch file1 files2 file3 mkdir command : It is used to create directories. Syntax: mkdir -option <dir name> When the <dir name> includes a pah name, option -p is used to create all non-existing parent directory.
  • 37. 37 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Example: #mkdir -p /export/home/ravi/test/test1 Removing Files and Directories : rm command: It is used permanently remove files/directories. The Syntax:rm -option <file name>/<dir name> The -i option is used to prompt user for confirmation before the deletion of files/directories. Example: We want to remove file1 and file2 from the home directory of user ravi. #pwd / #cd ~ravi #pwd /export/home/ravi #rm file1 file2 Note: The removal of a directory is slightly different. If the directory is not empty and you are trying to delete it, you will not be able to do so. You need to use -r option to remove the directory with files and sub-directories. Example: We want to delete a directory test under user ravi home directory and it contains file and sub-directories. #pwd /export/home/ravi #rm test rm: test is a directory #rm -r test # To remove an empty directory: Syntax: rmdir <directory name> Links (Soft Link and Hard Link) : This section has been covered under section :Solaris File System. Please refer to it. Searching Files, Directories & its contents: Using the grep command : The grep is very useful and widely used command. lets take an example where we want to see if the process statd is running of not. Following command is used : #ps -ef | grep statd # ps -ef | grep statd daemon 2557 1 0 Jul 07 ? 0:00 /usr/lib/nfs/statd
  • 38. 38 AshisChandraDas Infrastructure Sr.Analyst # Accenture > root 10649 1795 0 05:29:39 pts/4 0:00 grep statd # Syntax: grep options filenames. The options used are discussed below : i Searches both uppercase and lowercase characters l Lists the name of files with matching lines n Precedes each line with the relative line number in the file v Inverts the search to display lines that do not match pattern c Counts the lines that contain pattern w Searches for the expression as acomplete word, ignoring those matches that are sub strings of larger words Lets see few examples: Suppose we want to search for all lines that contain the keyword root in /etc/group file and view their line numbers, we use following option : # grep -n root /etc/group 1:root::0: 2:other::1:root 3:bin::2:root,daemon 4:sys::3:root,bin,adm 5:adm::4:root,daemon 6:uucp::5:root 7:mail::6:root 8:tty::7:root,adm 9:lp::8:root,adm 10:nuucp::9:root 12:daemon::12:root To search for all the lines that does not contain the keyword root: # grep -v root /etc/group staff::10: sysadmin::14: smmsp::25: gdm::50: webservd::80: postgres::90: unknown::96: nobody::60001: noaccess::60002: nogroup::65534: cta::101: rancid::102: mysql::103: torrus::104: To search for the names of the files that contains the keyword
  • 39. 39 AshisChandraDas Infrastructure Sr.Analyst # Accenture > root in /etc directory : # cd /etc # grep -l root group passwd hosts group passwd To count the number of lines containing the pattern root in the /etc/group file: # grep -c root group 11 Using regular expression Metacharacters with grep command: Metachar Purpose Example Result ^ Begining of line Anchor '^test' Matches all lines begining with test $ End of line anchor 'test$' Matches all the lines ending with test . Matches one char 't..t' Matches all the line starting and ending with t and 2 char between them * Matches the preceding item 0 or more times '[a-s]*' Matches all lines starting with lowercase a-s [] Matches one character in the pattern '[Tt]est' Matches lines containing test ot Test [^] Matches one character not in pattern '[^a- s]est' Matches lines that do not contain "a" though "s" and followed by est Using egrep command : With egrep we can search one or more files for a pattern using extended regular expression metacharacters. Following table describes the Extended Regular Expression Metacharacters : Metachar Purpose Example Result + Matches one of more preceding chars '[a-z]+est' Matches one or more lowercase letters followed by est(for example chest, pest, best, test, crest etc x|y Matches 'printer|scanner' Matches for either
  • 40. 40 AshisChandraDas Infrastructure Sr.Analyst # Accenture > either x or y expression (|) Groups characters '(1|2)+' or 'test(s|ing)' Matches for one or more occurrence. Syntax: egrep -options pattern filenames Examples: #egrep '[a-z]+day' /ravi/testdays sunday monday friday goodday badday In the above example, we searched for the letter ending with day in the file /ravi/testdays #egrep '(vacation |sick)' leave' /ravi/leavedata vacation leave on 7th march sick leave on 8th march In the above example we are displaying sick leave and vacation leave from file /ravi/leavedata Using fgrep command : It searches for all the character regardless of it being metacharacter as we have seen in case of grep and egrep commands. Syntax: fgrep options string filenames Example: #fgrep '$?*' /ravi/test this is for testing fgrep command $?* # Using Find command : This command is used to locate files and directories. You can relate it with windows search in terms of functionality. Syntax: find pathnames expressions actions Pathname: The absolute or relative path from where the search begins. Expressions: The search criteria is mentioned here. We will discuss search criteria below in details. Expression Definition -name filename Finds the file matching. -size [+|-]n Finds files that are larger than +n, smaller than
  • 41. 41 AshisChandraDas Infrastructure Sr.Analyst # Accenture > -n, or exactly n. -atime [+|- ]n Find files that have been accessed more than +n days, less than -n or exactly n days ago. -mtime [+|- ]n Find files that have been modified more than +n days, less than -n or exactly n days ago. -user loginID Finds all files that are owned by the loginID name. -type Finds a file type : f for file, d for directory. -perm Find files that have certain access permission bits. Action: Action required after all the files have been found. By default it displays all the matching pathnames Action Definition -exec command {} ; Runs the specified command on each file located. -ok commadn {} : Requires confirmation before the find command applies the command to each file located. -print Prints the search result -ls Displays the current pathname and associated stats : inode number, size in kb, protection mode, no. of hard links and the user. -user loginID Finds all files that are owned by the loginID name. -type Finds a file type : f for file, d for directory. -perm Find files that have certain access permission bits. Examples: #touch findtest #cat >> findtest This is for test. #find ~ -name findtest -exec cat {} ; This is for test. # The above examples searches for the file : findtest and displays its content. We can also use 'ok' option instead of exec. This will prompt for confirmation before displaying the contents of file findtest. If we want to find files larger than 10 blocks (1 block = 512bytes) starting from /ravi directory, following command is
  • 42. 42 AshisChandraDas Infrastructure Sr.Analyst # Accenture > used : #find /ravi -size +10 If we want to see all files that have not been modified in the last two days in the directory /ravi, we use : #find /ravi -mtime +2 Printing Files: lp comand : This command is located in /usr/bin directory. It is used to submit the print request to the printer. Syntax: /usr/bin/lp <file name> /usr/bin/lp -d <printer name > <file name> The options for the lp command are discussed below : Option Description d It is used to specify the desired printer. It is not required if default printer is used o It is used to specify that the banner page should not be printed n Print the number of copies specified m It send email after the print job is complete lpstat command : It displays the status of the printer queue. The Syntax for this command is as follows: lpstat -option <printer name> The options for the lpstat command are discussed below : Option Description p Displays the status of all printers o Displays the status of all output printers d Displays the default system printer t Displays the complete status information of all printers s Display the status summary of all printers a Displays which printers are accepting request The output of the lpstat command is in the following format : <request ID> <user ID> <File Size> <Date & Time> <status> Cancel command : It is used to cancel the print request. The Syntax: cancel <request ID>
  • 43. 43 AshisChandraDas Infrastructure Sr.Analyst # Accenture > cancel -u <user name> Note: We can use lpstat command to get the request ID. VI Editor VI Editor (Visual Editor) Its an editor like notepad in windows which is used to edit a file in SOLARIS. Unlike notepad it is very difficult to use. I wish the VI editor would have been developed by Bill gates rather than Bill Joy. Anways, guys we dont have any other option rather than getting aware of all these commands so that we become proficient in working with the VI Editor. Here are few commands that can be used while working with VI editor. There are three command modes in VI editor and we will see the commands based on the modes. Command Mode : This is default mode of the VI editor. In this mode we can delete, change, copy and move text. Navigation: Key Use j(or down arrow) To move the cursor to the next line (move down) k(or up arrow) To move the cursor to the previous line (move up) h(or left arrow) To move left one character l(or right arrow) To move right one character H To move the cursor to current page beginning of the first line. G To move the cursor to current page beginning of
  • 44. 44 AshisChandraDas Infrastructure Sr.Analyst # Accenture > the last line. b To move the cursor previous word first character e To move the cursor next word last character w To move the cursor to next word first character ^ Go to beginning of line 0 Go to beginning of line $ Go to the end of the line CTRL+F forward 1 screen CTRL+B backward 1 screen CTRL+D down (forward) 1/2 screen CTRL+U up (backward) 1/2 screen Copy & Paste: Key Use y+w To copy rest of the word from current cursor position. n+y+w To copy n number of words from the current cursor position. y+y To copy a line n+y+y To copy n lines p(lowerCase) To paste a copied words/lines after the current position of the cursor P(uppercase) To paste a copied words/lines before the current position of the cursor Deletion: Key Use x deletes a single character n+X To delete n number of characters from the cursor position in a line. d+w To delete rest of a word from current cursor position n+d+w To delete n number of words from the cursor position in a line d$ Delete rest of line from current cursor position D Delete rest of line from current cursor position d+d To delete an entire line n+d+d To delete n lines from current cursor position
  • 45. 45 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Few More Important Command Mode commands: Key Use u Undo changes (only one time) U Undo all changes to the current line ~ To change the case of the letter ZZ Saves the changes and quits the vi editor Input or Insert Mode: In this mode we can insert text into the file. We can enter the insert mode by pressing following keys in command mode: Key Use i Inserts the text before the cursor I Inserts the text at the beginning of the line o Opens a new blank line below the cursor O Opens a new blank line above the cursor a Appends text after the cursor A Appends the text after the line r replace the single character with another character R replace a entire line Esc To return to command mode Last line mode or Collan Mode : This is used for advance editing commands. To access the last line mode enter ":" while in command mode. Key Use : To get to collan mode(This need to be entered every time a user wants to use collan mode command) :+set nu Shows line numbers :+set nonu Hides line numbers
  • 46. 46 AshisChandraDas Infrastructure Sr.Analyst # Accenture > :+enter+n Moves the cursor to the n line :+/keyword To move the cursor to the line starting with the specific keyword :+n+d Deletes nth line :+5,10d Delete line from 5th line to 10th line :+7 co 32 Copies 7th line and paste in 32nd line :+10,20 co 35 Copies lines from 10th line to 20th line and paste it from 35th line :+%s/old_text/new_text/g Searches old string and replaces with the new string :+q+! Quits vi editor without saving :+w Saves the file with changes by writing to the disk :+w+q Saving and exit the vi editor :+w+q+! Saving and quitting the file forcefully 1,$s/$/" - type=Text_to_be_appended Append text at the end of the line Using VI Command: vi options <file name> The options are discussed below: -r : To recover a file from system crash while editing. -R : To open a file in read only mode. Viewing Files in Read Only Mode: view <file name> This is also used to open the file in read only mode. To exit type ':q' command. Automatic Customization of a VI session: 1. Create a file in the user's home directory with the name .exrc 2. enter the set variables without preceding colon 3. Enter each command in one line.
  • 47. 47 AshisChandraDas Infrastructure Sr.Analyst # Accenture > VI reads the .exrc file each time the user opens the vi session. Example: #cd ~ #touch .exrc #echo "set nu">.exrc #cat .exrc set nu # In the above example we have used set line number command. So whenever the user opens the vi session, line number is displayed.
  • 48. 48 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Working with Shell In this section we will play with shell. Shell is an interface between a user and the kernel. It is a command interpreter which interprets the commands entered by user and sends to kernel. The Solaris shell supports three primary shells: Bourne Shell: It is original UNIX system shell. It is default shell for root user. The default shell prompt for the regular user is $ and root is #. C Shell: It has several features which bourne shell do not have. The features are: It has command-line history, aliasing, and job control. The shell prompt for regular user is hostname% and for root user hostname#. Korn Shell: It is a superset of Bourne Shell with C shell like enhancements and additional features like command history, command line editing, aliasing & job control. Alternative shells: Bash(Bourne Again shell): It is Bourne compatible shell that incorporates useful features from Korn and C shells, such as command line history and editing and aliasing. Z Shell: It resembles Korn shell and includes several enhancements. TC Shell: It is completely compatible version of C shell with additional enhancements. Shell Metacharacters:
  • 49. 49 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Lets understand Shell Metacharacters before we can proceed any further. These are the special characters, generally symbols that has specific meaning to the shell.There are three types of metacharacters: 1. Pathname metacharacter 2. File name substitution metacharacter 3. Redirection metacharacter Path Name Metacharacters: Tilde (~) character: The '~' represents the home directory of the currently logged in user.It can be used instead of the user's absolute home path.Example : Lets consider ravi is the currently logged in user. #pwd / #cd ~ #pwd /export/home/ravi #cd ~/dir1 #pwd /export/home/ravi/dir1 #cd ~raju #pwd /export/home/raju Note: '~' is available in all shells except Bourne shell. Dash(-) character: The '-' character represents the previous working directory.It can be used to switch between the previous and current working directory. Example: #pwd / #cd ~ #pwd
  • 50. 50 AshisChandraDas Infrastructure Sr.Analyst # Accenture > /export/home/ravi #cd - #pwd / #cd - #pwd /export/home/ravi File Name Substitution Metacharacters : Asterisk (*) Character: It is a called wild card character and represents zero or more characters except for leading period '.' of a hidden file. #pwd /export/home/ravi #ls dir* dir1 dir2 directory1 directory2 # Question Mark (?) Metacharacters: It is also a wild card character and represents any single character except the leading period (.) of a hidden file. #pwd /export/home/ravi #ls dir? dir1 dir2 # Compare the examples of Asterisk and Question mark metacharacter and you will get to know the difference. Square Bracket Metacharacters: It represents a set or range of characters for a single character position. The range list can be anything like : [0-9], [a-z], [A-Z]. #ls [a-d]* apple boy cat dog
  • 51. 51 AshisChandraDas Infrastructure Sr.Analyst # Accenture > # The above example will list all the files/directories starting with either 'a' or 'b' or 'c' or 'd'. #ls [di]* dir1 dir2 india ice # The above example will list all the files starting with either 'd' or 'i'. Few shell metacharacters are listed below: Metacharacter Description ~ The '~' represents the home directory of the currently logged in user - The '-' character represents the previous working directory * A wild card character that matches any group of characters of any length ? A wild card character that matches any single character $ Indicates that the following text is the name of a shell (environment) variable whose value is to be used | Separates command to form a pipe and redirects the o/p of one command as the input to another < Redirect the standard input > Redirect the standard output to replace current contents >> Redirect the standard output to append to current contents ; Separates sequences of commands (or pipes) that are on one line Used to "quote" the following metacharacter so it is treated as a plain character, as in * & Place a process into the background Korn Shell Variables: It is referred to as temporary storage area in memory.It enables us to store value into the variable. These variables are of two types :
  • 52. 52 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 1. Variables that are exported to subprocesses. 2. Variables that are not exported to subprocesses. Lets check few commands to work with these variables: To set a variable : #VAR=value #export VAR Note: There is no space on the either side of the '=' sign. To unset a variable: #unset VAR To display all variables: We can use 'set' or 'env' or 'export' command. To display value of a variable: echo $VAR or print $VAR Note: When a shell variable follows $ sign, then the shell substitutes it by the value of the variable. Default Korn Shell Variables : EDITOR : The default editor for the shell. FCEDIT : It defines the editor for the fc command. HOME : Sets the directory to which cd command switches. LOGNAME : Sets the login name of the user. PATH : It specifies the paths where shell searches for a command to be executed. PS1 :It specifies the primary korn shell ($) PS2 : It specifies the secondary command prompt (>) SHELL : It specifies the name of the shell. Using quoting characters: Quoting is the process that instructs the shell to mask/ignore the special meaning of the metacharacters. Following are few
  • 53. 53 AshisChandraDas Infrastructure Sr.Analyst # Accenture > use of the quoting characters: Single quotation mark (''): It instructs the shell to ignore all enclosed metacharacters. Example: #echo $SHELL /bin/ksh #echo '$SHELL' $SHELL # Double quotation mark (""): It instructs the shell to ignore all enclosed shell metacharacters, except for following : 1. The single backward quotation(`) mark : This executes the solaris command inside the single quotation.Example: # echo "Your current working directory is `pwd`" Your current working directory is /export/home/ravi In the above example the '`' is used to execute the 'pwd' command inside the quotation mark. 2. The blackslash() in the front of a metacharacter : This ignores the meaning of the metacharacter.Example: #echo "$SHELL" /bin/ksh #echo "$SHELL" $SHELL In the above example, the inclusion of '' ignores the meaning of metacharacter '$' 3. The '$' sign followed by command inside parenthesis : This executes the command inside the parenthesis.Example: # echo "Your current working directory is $(pwd)" Your current working directory is /export/home/ravi In the above example enclosing the pwd command inside
  • 54. 54 AshisChandraDas Infrastructure Sr.Analyst # Accenture > parenthesis and $ sign before parenthesis, executes the pwd command. Displaying the command history: The shell keeps the history of all the commands entered. We can re-use this command in our ways. For a given user this list of command used is shared among all the korn shells. Syntax: history option The output will somewhat like following : ... 125 pwd 126 date 127 uname -a 128 cd The numbers displayed on the left of the command are command numbers and can be used to re-execute the command corresponding to it.To view the history without command number -n option is used : #history -n To display the last 5 commands used along with the current command : #history -5 To display the list in reverse order: #history -r To display most recent pwd command to the most recent uptime command, enter the following: #history pwd uptime Note: The Korn shell stores the command history in file specified by the HISTFILE variable. The default is the ~/.sh_history file. By default shell stores most recent 128 commands. Note: The history command is alias for the command "fc -l". The 'r' command : The r command is an alias in Korn Shell that enables us to repeat a command. Example: #pwd /export/home/ravi
  • 55. 55 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #r /export/home/ravi This can be used to re-execute the commands from history. Example: #history ... 126 pwd 127 cd 128 uname -a #r 126 /export/home/ravi The 'r' command can also be used to re-execute a command beginning with a particular character, or string of characters. Example: # r p pwd /export/home/ravi # In the above example the 'r' command is used to re-run the most recent occurrence of the command starting with p. #r ps ps -ef o/p of ps -ef command In the above example the 'r' command is used to re-run the most recent command starting with ps. We can also edit the previously run command according to our use. The following example shows that : #r c cd ~/dir1 #r dir1=dir cd ~/dir In this example the cd command has re-run but the argument passed to it has been changed to dir from dir1.
  • 56. 56 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Note: The r command is alias for the command " fc -e - ". Editing the previously executed commands using vi-editor : We can also edit the previously executed command under history using vi-editor. To do so, we need to enable shell history editing by using any one of the following commands : #set -o vi or #export EDITOR=/bin/vi or #export VISUAL=/bin/vi To verify whether this feature is turned on, use the following command : #set -o | grep -w vi vi on Once it is on you can start editing the command history as follows : 1. Execute the history command: #history 2. Press Esc key and start using the vi editing options. 3. To run a modified command, press enter/return key. File Name Completion : Suppose you are trying to list files under the directory "/directoryforlisting". This is too big to type. There is a short method to list this directory. Type ls d and then press Esc and then (backslash) key. The shell completes the file name and will display : #ls directoryforlisting/ We can also request to display all the file name beginning with 'd' by pressing Esc and = key
  • 57. 57 AshisChandraDas Infrastructure Sr.Analyst # Accenture > sequentially. Two points to be noted here : 1. The key sequence presented above works only in the vi mode of the command line editing. 2. The sequence in which the key is pressed is important. Command Redirection: There are two redirection commands: 1. The greater than (>) sign metacharacter 2. The less than (<) sign metacharacter Both the above mentioned mentioned commands are implied by pipe (|) character. The File Descriptors: Each process works with shell descriptor. The file descriptor determines where the input to command originates and where the output and error messages are sent. File Descriptor Number File Description Abbreviation Definition 0 stdin Standard Command input 1 stdout Standard Command output 2 stderr Standard Command error All command that process file content read from the standard input and write to standard output. Redirecting the standard Input: command < filename or command 0<filename The above command the "command" takes the input from "filename" instead of keyboard.
  • 58. 58 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Redirecting the standard Output: command > filename or command 1>filename #ls -l ~/dir1 > dirlist The above command redirects the output to a file 'dirlist' instead of displaying it over the terminal. command >> filename #ls -l ~/dir1 >> dirlist The above example appends the output to the file 'dirlist'. Redirecting the Standard Error: command > filename 2> <filename that will save error> command> filename 2>&1 The first example will redirect the error to the file name specified at the end. The second example will redirect the error to the input file itself. The Pipe character : The pipe character is used to redirect the output of a command as input to the another command. Syntax: command | command Example: # ps -ef | grep nfsd In the above example the output of ps -ef command is send as input to grep command. #who | wc -l User Initialization Files Administration : In this section we will see initialization files of Bourne, Korn and C shell. Initialization files at Login /bin/ksh Shell System wide Initializati Primary user Initialization F User Initializati Shell Pathnam
  • 59. 59 AshisChandraDas Infrastructure Sr.Analyst # Accenture > on File ile Read at Login on Files Read When a New Shell is Started e Bourn e /etc/profile $HOME/.profile /bin/sh Korn /etc/profile $HOME/.profile $HOME/.kshrc /bin/ks h $HOME/.kshrc C /etc/.login $HOME/.cshrc $HOME/.cshrc /bin/cs h $HOME/.login Bourne Shell Initialization file: The .profile file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application. Korn Shell Initialization file: It has two initialization file : 1. The ~/.profile: The .profile file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application. 2. The ~/.kshrc: It contains shell variables and aliases. The system executes it every time the user logs in and when a ksh sub-shell is started. It is used to define Korn shell specific settings. To use this file ENV variable must be defined in .profile file. Following settings can be configured in /.kshrc file : Shell prompt definations (PS1 & PS2) Alias Definitions
  • 60. 60 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Shell functions History Variables Shell option ( set -o option) The changes made in these files are applicable only when the user logs in again. To make the changes effective immediately, source the ~/.profile and ~/.kshrc file using the dot(.) command: #. ~/.profile #. ~/.kshrc Note: The /etc/profile file is a separate system wide file that system administrator maintains to set up tasks for every user who logs in. C Shell Initialization file: It has two initialization file : 1. The ~/.cshrc file : The . cshrc file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application. Following settings can be configured in .cshrc file : Shell prompt definations (PS1 & PS2) Alias Definitions Shell functions History Variables Shell option ( set -o option) 2. The ~/.login file: It has same functionality as .cshrc file and has been retained for legacy reasons. Note: The /etc/.login file is a separate system wide file that system administrator maintains to set up tasks for every user who logs in. The changes made in these files are applicable only when the user logs in again. To make the changes effective immediately,
  • 61. 61 AshisChandraDas Infrastructure Sr.Analyst # Accenture > source the ~/.cshrc and ~/.login file using the source command: #source ~/.cshrc #source ~/.login The ~/.dtprofile file : It resides in the user home directory and determines generic and customized settings for the desktop environment.The variable setting in this file can overwrite the default desktop settings. This file is created when the user first time logs into the desktop environment. Important: When a user logins to the desktop environment, the shell reads .dtprofile, .profile and .kshrsc file sequentially. If the DTSOURCEPROFILE variable under .dtprofle is not ture or does not exists, the .profile file is not read by the shell. The shell reads .profile and .kshrsc file when user opens console window. The shell reads .kshrsc file when user opens terminal window. Configuring the $HOME/.profile file: It can be configured to instruct the login process to execute the initialization file referenced by ENV variable. To configure that we need to add the following into the $HOME/.profile file: ENV=$HOME/.kshrc export ENV Configuring the $HOME/.kshrc file : This file contains korn shell specific setting.To configure PS1 variable, we need to add the following into the $HOME/.kshrc file: PS1="''hostname' $" export PS1
  • 62. 62 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Advanced Shell Functionality: In this module we will learn four important aspects of Korn shell. Managing Jobs in Korn Shell: A job is a process that the shell can manage. Each job has a process id and it can be managed and controlled from the shell. The following table illustrates the job control commands: Command Value jobs List all jobs that are currently running or stopped in the background bg %<jobID> Runs the specified job in background fg %<jobID> Brings the specified job in foreground Ctrl+Z Stops the foreground job and places it in the background as a stopped job stop %<jobID> Stops a job running in background Note: When a job is placed either in foreground or background, the job restarts. Alias Utility in Korn Shell : Aliases in Korn shell can be used to abbreviate the commands for the ease of usage. Example: we are frequently using the listing command: ls -ltr. We can create alias for this command as follows: #alias list='ls -ltr' Now when we type the 'list' over shell prompt and hit return, it replaces the 'list' with the command 'ls -ltr' and executes it. Syntax : alias <alias name>='command string' Note: 1. There should not be any space on the either side of the '=' sign. 2. The command string mustbe quoted if it includes any options, metacharacters, or spaces. 3. Each command in a single alias must be separated with a semicolon.e.g.:#alias info='uname -a; date' The Korn shell has predefines aliases as well which can be listed by using 'alias' command: #alias ..
  • 63. 63 AshisChandraDas Infrastructure Sr.Analyst # Accenture > stop='kill -STOP' suspend='kill -STOP $$' .. Removing Aliases: Syntax: unalias <alias name> Example: #unalias list Korn Shell functions : Function is a group of commands organized together as a separate routine. Using a function involves two steps : 1. Define the function: function <function name> { command;...command; } A space must appear after the first brace and before the closing brace. Example: #function HighFS{ du -ak| sort -n| tail -10; } The above example defines a function to check the top 10 files using most of the space under current working directory. 2. Invoke the function : If we want to run the above defined function, we just need to call it by its name. Example: #HighFS 6264 ./VRTSvcs/conf/config 6411 ./VRTSvcs/conf 6510 ./VRTSvcs 11312 ./gconf/schemas 14079 ./gconf/gconf.xml.defaults/schemas/apps 16740 ./gconf/gconf.xml.defaults/schemas 17534 ./gconf/gconf.xml.defaults 28851 ./gconf 40224 ./svc 87835 . Note: If a function and an alias are defined by the same name, alias takes precedence. To view the list of all functions : #typeset -f -> This will display functions as well as their definitions. #typeset +f -> This will display functions name only. Configuring the Shell Environment variable: The shell secondary prompt sting is stored in the PS2 shell variable, and it can be customized as follows: #PS2="Secondary Shell Prompt" #echo PS2
  • 64. 64 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Secondary Shell Prompt # To display the secondary shell prompt in every shell, it must be included in the user's Korn Shell initialization file(.kshrc file) Setting Korn Shell options : Korn Shell options are boolean (on or off). Following is the Syntax: To turn on an option: #set -o option_name To turn off an option: #set +o option_name To display current options: # set -o Example: #set -o noclobber #set -o | grep noclobber noclobber on The above example sets the noclobber option. When this option is set, shell refuses to redirect the standard output to a file and displays error message on the screen. #df -h > DiskUsage #vmstat > DiskUsage ksh: DiskUsage: file already exists # To deactivate the noclobber option : #set +o noclobber Shell Scripts: It is a text file that has series of command executed one by one. There are different shell available in Solaris. To ensure that the correct shell is used to run the script, it should begin with the characters #! followed immediately by the absolute pathname of the shell. #!/full_Pathname_of_Shell Example: #!/bin/sh #!/bin/ksh Comments: It provides information about the script files/commands. The text inside the comment is not executed. The comment starts with character '#'. lets write our first shell script :
  • 65. 65 AshisChandraDas Infrastructure Sr.Analyst # Accenture > #cat MyFirstScript #!/bin/sh ls -ltr #This is used to list the files/directories Running a Shell Script : The shell executes the script line by line. It does not compile the script and keep it in binary form. So, In order to run a script, a user must have read and execute permission. Example: #./MyFirstScript The above example runs the script in sub-shell. If we want to run the script as if the commands in it were ran in same shell, the dot(.) command is used as follows: #. ./MyFirstScript Passing Value to the shell script: We can pass value to the shell script using the pre-defined variables $1, $2 and so on. These variables are called Positional Parameters. When the user run the shell script, the first word after the script name is stored in $1, second in $2 and so on. Example: #cat welcome #!/bin/sh echo $1 $2 #welcome ravi ranjan ravi ranjan In the above example when we ran the script welcome, the two words after it ravi and ranjan was stored in $1 and $2 respectively. Note: There is a limitation in Bourne shell. It accepts only a single number after $ sign. So if we are trying to access the 10th argument $10, it will result in the value of $1 followed by (0). In order to overcome this problem, shift command is used. Shift Command: It enables to shift the value of positional parameter values back by one position i.e. the value of $2 parameter is assigned to $1, and $3 to $2, and so on. Checking Exit status: All commands under Solaris returns an exit status. The value '0' indicates success and non-zero value ranging from 1-255 represents failure. The exit status of the last command run under foreground is held in ? special shell variable. # ps -ef | grep nfsd root 6525 22601 0 05:55:01 pts/11 0:00 grep nfsd
  • 66. 66 AshisChandraDas Infrastructure Sr.Analyst # Accenture > # echo ? 1 # In the above example there is no nfsd process running, hence 1 is returned. Using the test Command: It is used for testing conditions. It can be used to verify many conditions, including: Variable contents File Access permissions File types Syntax : #test expression or #[ expression ] The test builtin command returns 0 (True) or 1 (False), depending on the evaluation of an expression, expr. Syntax:test expr or [ expr ] We can examine the return value by displaying $?; We can use the return value with && and ||; or we can test it using the various conditional constructs. We can compare arithmetic values using one of the following: Option Tests for Arithmetical Values -eq equal to -ne not equal to -lt less than -le less than or equal to -gt greater than -ge greater than or equal to We can compare strings for equality, inequality etc. Following table lists the various options that can be used to compare strings: Option Tests for strings = equal to. e.g #test "string1" = "string2" != not equal to. e.g #test "string1" = "string2" < less than. e.g #test "ab" < "cd"
  • 67. 67 AshisChandraDas Infrastructure Sr.Analyst # Accenture > > greater than. e.g #test "ab" > "cd" " -z for a null string. e.g #test -z "string1" -n returns True if a string is not empty. e.g. #test -n "string1" Note: the < and > operators are also used by the shell for redirection, so we must escape them using < or >. Example : Lets test that the value of variable $LOGNAME is ravi. #echo $LOGNAME ravi # test "LOGNAME" = "ravi" #echo $? 0 #[ "LOGNAME" = "ravi" ] #echo $? 0 Lets test if read permissions on the /ravi #ls -l /ravi -rw-r--r-- 1 root sys 290 Jan 10 01:10 /ravi #test -r /ravi #echo $? 0 #[ -r /ravi ] #echo $? 0 Lets test if /var is a directory #test -d /var #echo $? 0 #[ -d /var ] #echo $? 0
  • 68. 68 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Executing Conditional Commands : In this section we will see the following three conditional commands: 1. Using If command: It checks for the exit status of the command and if exist status is (0), then the statement are run other wise statement under else is executed. Syntax: #if command1 >then >execute command2 >else >execute command3 >fi The shell also provides two constructs that enable us to run the command based on the success or failure of the preceding command. The constructs are &&(and) and ||(or). Example: #mkdir /ravi && /raju This command creates directory /raju only if /ravi is created. #mkdir /ravi || /raju This command creates directory /raju even if /ravi fails to create. 2. Using while command: It enables to repeat a command or group of command till the condition returns (0). Syntax: #while command1 >do >command2 >done 3. Using case command: It compares a single value against other values and runs a command or commands when a match is found. Syntax: #case value in >pat1)command >command >.. >command >;; >pat2)command >command >.. >command >;; ...
  • 69. 69 AshisChandraDas Infrastructure Sr.Analyst # Accenture > >patn)command >command >.. >command Process Management Process: Every program in Solaris runs as a process and there is a unique PID attached with each process. The process started/run by OS is called Daemon. It runs in background and provides services. Each process has a PID, UID and GID associated with it. UID indicates the user who owns the process and GID denotes the group to which owner belongs to. When a process creates another process, then the new process is called Child Process and old one is called Parent Process. Viewing Process: ps command: It is used to view process and is discussed below. Syntax: ps options Few options are discussed below: Option Description -e Prints info about every process on the system including PID, TTY(terminal identifier), TIme & CMD -f Full verbose listing which includes UIDm parent PID, process start time(STIME) Example: #ps -ef | more UID PID PPID C STIME TTY TIME CMD root 0 0 0 Jun 02 ? 2:18 sched root 1 0 0 Jun 02 ? 1:47 /sbin/init root 2 0 0 Jun 02 ? 0:13 pageout root 3 0 0 Jun 02 ? 110:25 fsflush daemon 140 1 0 Jun 02 ? 0:15 /usr/lib/crypto/kcfd root 7 1 0 Jun 02 ? 0:28 /lib/svc/bin/svc.startd --More--
  • 70. 70 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Now let us understand the above output column wise : Column Description UID User Name of the process owner PID Process ID PPID Parent Process ID C The CPU usage for scheduling STIME Process start time TTY The controlling terminal for process. For daemons '?' is displayed as it is started without any terminal. TIME The cumulative execution time for the process. CMD The command name, options, arguments We can also search specific process using ps and grep command. For Example, if we want to search for nfsd process, we using the following command : -sh-3.00$ ps -ef | grep nfsd daemon 2127 1 0 Jul 06 ? 0:00 /usr/lib/nfs/nfsd ravi 26073 23159 0 03:05:49 pts/175 0:00 grep nfsd -sh-3.00$ pgrep command: It is used to search process by process name and displays PID of the process. Syntax : pgrep options pattern The options are described below: Option Description -x Displays the PID that matches exactly -n Displays only the most recently created PID that matches the pattern -U uid Displays only the PIDs that belong to the specific user. This option uses either a user name or a UID -l Displays the name of the process along with the PID -t term Displays only those processes that are associated with a terminal in the term list Examples: -sh-3.00$ pgrep j 3440 1398 -sh-3.00$ pgrep -l j
  • 71. 71 AshisChandraDas Infrastructure Sr.Analyst # Accenture > 3440 java 1398 java -sh-3.00$ pgrep -x java 3440 1398 -sh-3.00$ pgrep -n java 1398 -sh-3.00$ pgrep -U ravi 28691 28688 Using the ptree command: It displays a process tree based on the process ID passed as an argument. An argument of all digits are taken to be a PID, otherwise it is assumed to be a user login name. Sending a Signal to a process: Signal is a messages that is send to a process. The process responds back by performing the action that the signal requests. It is identified by a signal number and by a signal name. There is an action associated to each signal. Signal No. Signal Name Event Definition Default Response 1 SIGHUP Hang Up It drops a telephone line or terminal connection. It also causes some program to re-intialize itself without terminating Exit 2 SIGINT Interrupt Its it generated from Key board. e.g. ctrl+C Exit 9 SIGKILL Kill It kills the process and a process cant ignore this signal Exit 15 SIGTERM Terminate It terminates the process in orderly manner. This is the default signal that kill & pkill send. Exit Using kill Command: It is used to send signal to one or more processes and terminates only those process that is owned by the user. A root user can kill any process. This command sends signal 15 to the process.
  • 72. 72 AshisChandraDas Infrastructure Sr.Analyst # Accenture > Syntax: kill [-signals] PIDs Examples: # pgrep -l java 2441 java #kill 2441 If the process does not terminates, issue signal 9 to forcefully terminate the process as below : #kill -9 2441 Using pkill Command: It is used to terminate the process with signal 15. We can specify the process names(to be terminated) also in this command. Syntax: pkill [-options] pattern The options are same as that of pgrep command. Example: #pkill java We can force the process to terminate by using signal 9: #pkill -9 -x java Solaris File System Understanding the SOLARIS file system is very important, before we discuss anything further. Its huge topic and I suggest you really need to be patient while going through it. If you find anything difficult to understand, you can comment and I will get back to you as soon as possible. File is the basic unit in Solaris, similar to atom for an element in chemistry. For example commands are executable files, documents are text file or file having code/script, directories are special files containing other files etc. Blocks: A file occupies the space on disks in units. These units are called Blocks. The blocks are measured in two sizes : 1. Physical Block size: Its the size of the smallest block that the disk controller can read or write. The physical block size is usually 512B for UFS(Unix Files System). It may vary from file system to file system. 2. Logical Block size: Its the size of the block that UNIX
  • 73. 73 AshisChandraDas Infrastructure Sr.Analyst # Accenture > uses to read or write files. It is set by default to the page size of the system, which is 8KB for UFS. Inodes: It is a data structure that contains all the file related information except the file name and data. It is 128 kb in size and is stored in cylindrical information block. The inode contains following information about a file : 1. Type of File : e.g. regular file, block special, character special, directory, symbolic link, other inode etc. 2. The file modes : e.g. read, write, execute permissions. 3. The number of hard links to the file. 4. The group id to which the file belongs 5. The user ID that owns the file. 6. The number of bytes in the file. 7. An array of addresses for 15 disk blocks 8. The date and time when the file was created, last accessed and last modified. So, an Inode contains almost all the information about a file. But what is more important is what an inode does not contain. An inode does not contain the "file name" and data. The file name is stored inside a directory and data is saved in blocks There is an inode associated with each file. So, the number of inodes determines the maximum number of files in the files system. The number of inodes depends upon the size of file system. For example : lets take a file system of size 2gb. The inode size will be 4kb each. So the number of inodes = 2gb /4kb = 524288. So the maximum number of files that can be created is 524288. File system: Its the way an operating system organizes files on a medium(storage device).
  • 74. 74 AshisChandraDas Infrastructure Sr.Analyst # Accenture > The different flavors of UNIX have different default file systems. Few of them are listed below: SOLARIS - UFS (Unix File System) AIX - JFS (journal FS) JP - HFS (high performance FS) LINUX - ext2 & ext3 Before getting into the UFS file system, lets discuss about the architecture of the file system in SOLARIS and other file systems used in SOLARIS. SOLARIS uses VFS (Virtual File System architecture). It provides standard interface for different file system types. The VFS architecture enables kernel to perform basic file operation such as reading, writting and listing. Its is called virtual because the user can issue same command to work regardless of the file system. SOLARIS also uses memory based file system and disk based file system. Lets discuss some memory based file systems: Memory based File Systems: It use the physical memory rather than disk and hence also called Virtual File System or pseudo file system. Following are the Memory based file system supported by SOLARIS: 1. Cache File System(CacheFS): It uses the local disk to cache the data from the slow file systems like CD - ROM. 2. Loopback File System(LOFS): If we want to make a file system e.g: /example to look like /ex, we can do that by creating a new virtual file system known as Loopback File System. 3. Process File System(PROOFS): It is used to contains the list of active process in SOLARISby their process ID, in the /proc directory. It is used by the ps command. 4. Temporary File System(TEMPFS): It is the temporary file