Friday 24 July 2015

AIX - Tips n Tricks - Part II

1. How to configure the system and create a restricted shell user ?
Below example shows how to create a restricted shell user (this user can execute only "ls" and "vi" commands
a) Make a reduced bin directory to contain links to programs for the user or users: 
# mkdir /usr/rbin
b) Link the necessary commands and programs in the reduced bin directory.
For example, give access to the ls and vi commands:
# ln -s /usr/bin/ls /usr/rbin/ls
# ln -s /usr/bin/vi /usr/rbin/vi
c) Add Rsh as a valid shell in /etc/security/login.cfg:
# vi /etc/security/login.cfg
d) Add /usr/bin/Rsh to the list of shells in the usw stanza:
usw:
shells = /bin/sh,/bin/bsh,/bin/csh,/bin/ksh,/bin/tsh,/bin/ksh93,/usr/bin/sh,
/usr/bin/bsh,/usr/bin/csh,/usr/bin/ksh,/usr/bin/tsh,/usr/bin/ksh93,/usr/sbin/
uucp/uucico,/usr/sbin/sliplogin,/usr/sbin/snapp,/usr/bin/Rsh
e) Add the restricted shell user:
# mkuser shell="/usr/bin/Rsh" alex
f) Assign an initial password:
# passwd alex
g) Change the ownership of the users profile to root:
# chown root:system /home/alex/.profile
h) Change the permissions of the users profile to 755:
# chmod 755 /home/alex/.profile
i) Edit the users profile setting the PATH and Shell variables:
# vi /home/alex/.profile
Set PATH for the new bin directory and Set SHELL to rksh:
PATH=/usr/rbin; export SHELL=/usr/bin/Rsh
---------------------------------------------------------------------------­---------------------------------
2. How to change the default welcome (herald) message on the login display ?
Edit the file /etc/security/login.cfg and update the herald parameter ...
default:
herald = "Unauthorized use of this system is prohibited\n\nlogin: "
sak_enable = false
logintimes =
logindisable = 0
logininterval = 0
loginreenable = 0
logindelay = 0
You can also use the below command to change the herald value
# chsec -f /etc/security/login.cfg -a default -herald "Unauthorized use of this system is prohibited.\n\nlogin: "
---------------------------------------------------------------------------­---------------------------------
3. How to set automatic logoff (only for terminals) ?
Edit the /etc/security/.profile file to include an automatic logoff value for all users, as in the following example:
TMOUT=600 ; TIMEOUT=600 ; export readonly TMOUT TIMEOUT
The number 600, in this example, is in seconds, which is equal to 10 minutes. However, this method only works from the shell.
---------------------------------------------------------------------------­---------------------------------
4. How to auto forward the mails ?
Create $HOME/.forward file and add adresses or aliases.
When mail is sent to a local user, the sendmail command checks for the $HOME/.forward file.
If the file exists, the message is not sent to the user. The message is sent to the addresses or aliases in the $HOME/.forward file.
---------------------------------------------------------------------------­---------------------------------

5. How to set(define) and unset a variable in a shell or shell script ?
# x=3 -> Defines a vlue for a variable 'x'
# echo $x -> Displays the vlue of 'x' vairable
3
# unset x -> Unsets the variable
# echo $x -> Again display its value
#
---------------------------------------------------------------------------­---------------------------------

6. How to send file1 as a message to user alex ?
# mail alex <>
---------------------------------------------------------------------------­---------------------------------

7. How to display mail queue ?

Note: mailq is the queue where your mails are stored
# mailq (or) sendmail -bp
There is 1 request in the mail queue
---QID---- --Size-- -----Q-Time----- ----------Sender/ Recipient-----------
OAA 19258 * 29 Mon Jun 26 14:57 root
---------------------------------------------------------------------------­---------------------------------

8. Whats sendmail command?
It receives formatted messages and routes messages to one or more users. IT can deliver messages to users on local/remote machines. It will be started by tcpip sub-system . It uses /etc/mail/sendmail.cf as config file.
Once this daemon started, you can find its process id in
/etc/sendmail.pid.

---------------------------------------------------------------------------­---------------------------------

9. How to define mail aliases for users?
a) Add the aliases to /etc/aliases.
For Example,
nobody: /dev/null
certify: user02, user5801@server3, root@server4, user5911@se
b) Rebuild the aliases database using
newaliases (or) sendmail -bi
---------------------------------------------------------------------------­---------------------------------

10. If logging with telnet takes long time (for ex. 2 mins), what might be the issue?
There might be problem with DNS resolution. Check /etc/resolv.conf and check dns connection thru nslookup command.
---------------------------------------------------------------------------­---------------------------------
11. While attempting to log in, you see the below message. How you solve this issue ?
'All available login sessions are in use.'
Check the number of AIX user license using "lslicense"
If required increase the license using "chlicense" command.
---------------------------------------------------------------------------­---------------------------------
12. Oracle DBA says that his database is not able to go beyond certain limit. For example, oracle userid is not able to start more than 500 process's. Whats the issue?
This is because of the "maxuproc" value is 500. Check the value using "lsattr -El sys0 -a maxuproc"
If required change the value using
# chdev -l sys0 -a maxuproc=1000
Normally for Oracle Production machines, you have to consult with DBA's while installing the server and set an agreed value.
---------------------------------------------------------------------------­---------------------------------
13. Errpt is not displaying any reports. Found that /var/adm/ras/ errlog file is there in the location and errdemon is running fine. What might be the issue the issue?
errlog file seems to be corrupted. Delete the file and stop the errdemon (/usr/lib/errstop).
Start the errdaemon (/usr/lib/errdemon). While starting, daemon creates the errlog file automatically.
---------------------------------------------------------------------------­---------------------------------
14. How to list IDE controllers in your system ?
# lscfg -l ide*
DEVICE LOCATION DESCRIPTION
ide0 01-00-00 ATA/IDE Controller Device
ide1 01-00-01 ATA/IDE Controller Device
The following sample display from the lscfg -l ide command shows
There are 2 IDE I/O controllers configured in the server
Controller ide0 and ide1 are located on the system planar ( Notice 1st and 2nd digits in location code)

The planar indicator is the second digit in the location value with a value of 1.
6th digit indicates the controller number.
---------------------------------------------------------------------------­---------------------------------
15. After a successful login, the login command displays the message of the day, the date and time of the last successful and unsuccessful login attempts for this user, and the total number of unsuccessful login attempts for this user since the last change of authentication information (usually a password).
How do you suppress these messages?
You can suppress these messages by creating a “.hushlogin” file in your home directory.
For Example,
At the prompt in your home directory, type the following:
# touch .hushlogin
The touch command creates the empty file named .hushlogin if it does not already exist. The next time you log in, all login messages will be suppressed. You can instruct the system to retain only the message of the day, while suppressing other login messages.
---------------------------------------------------------------------------­---------------------------------
16. Whats the files system read once you login ?
First File : /etc/environment - contains variables specifying the basic environment for all processes.
Second File: /etc/profile - controls system-wide default variables
Third File : $HOME/.profile - lets you customize your individual working environment
Fourth File: $HOME/.env - lets you customize your individual working environment variables.
---------------------------------------------------------------------------­---------------------------------
17. How to override variables defined in /etc/environment for a particular user?
A fourth file that the operating system uses at login time is the
$HOME/.env file, if your .profile contains the following line:
export ENV=$HOME/.env
The .env file lets you customize your individual working environment variables. The .env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your .env file.
---------------------------------------------------------------------------­---------------------------------
18. How to change the font in AIX ?
To change the font to an italic, roman, and bold face of the same size, type the following:
# chfont -n /usr/lpp/fonts/It114.snf /usr/lpp/fonts/Bld14.snf /usr/lpp/
> fonts/Rom14.snf
You can also use smitty chfont.
---------------------------------------------------------------------------­---------------------------------
19. How to run a process in the background ?
For Ex, to run script1.sh in background run
# script1.sh &
But this script process gets killed if you close the terminal
So always practice to run using nohup,
# nohup script1.sh &
Usage of nohup doesn't kill the process if you close the telnet session. Output from the process/script will be stored in a file called nohup.out in the directory from where you started the process.
This will help you in case if you want to start backup using mksysb and close your terminal/ leaving office, you can safely use "nohup command &". Next day morning, you can view the contents of nohup.out to know the status of the backup job.
---------------------------------------------------------------------------­---------------------------------
20. What is the default priority for a process?
Default priority is 0. Priority numbers is in the range of -20 to 20. Highest number is the lowest priority and lowest number has high priority while using resources.
To set the priority while start a process, use nice command.
If the process is already running, you can use "renice" command to change its priority.
---------------------------------------------------------------------------­---------------------------------
21. How to stop, resume and to make it foreground process?
To stop(pause) a foreground process, use
Cntrol + Z keys ie., Ctrl+Z.
Note: Ctrl+Z works in the Korn shell (ksh) and C shell (csh), but not in the Bourne shell (bsh).
To restart a stopped process, you must either be the user who started the process or have root user authority.
To restart a stopped process, enter
# kill -19 pid
To run it in foreground, enter
# fg pid

where pid is the process id which can be obtained from the following command
ps -ef | grep precess_name | awk '{print $2}'
---------------------------------------------------------------------------­---------------------------------
22. How to display a program output as well as copying to a file ?
Normally usage of output redirection suppresses the output on screen.

Ex. ls -l > file1
If we want to redirect the output as well as show the output in screen use the tee command.
Ex: ls -l | tee -a file1
---------------------------------------------------------------------------­---------------------------------
23..How to capture your terminal screen to a file ?
To capture the screen of a terminal, at the prompt, type the following:
#script
The system displays information similar to the following:
Script command is started. The file is typescript.
Everything displayed on the screen is now copied to the "typescript" file.
To stop the script command, press Ctrl-D or type exit and press Enter.
The system displays information similar to the following:
^D
Script command is complete. The file is typescript.
Use the cat command to display the contents of your file.
---------------------------------------------------------------------------­---------------------------------
24. What are the supported file systems in AIX ?
a) JFS (or) JFS2 - Disk based file system
b) NFS - Network based File system
c) CDRFS - CDROM based file system
d) UDFS - DVD-ROM based file system
e) RAMFS - RAM based file system used while booting the system
---------------------------------------------------------------------------­---------------------------------

25. What are the different directory abbreviations?
Abbreviation Meaning
. The current working directory
.. The parent of the current working directory
~ Your home directory
$HOME Your home directory
---------------------------------------------------------------------------­---------------------------------
26. What are the different directory path names ?
Absolute path name:
Traces the path from the /(root) directory. Absolute path names always
begin with the slash (/) symbol.
Ex. /home/ raja/dir1

Relative path name:
Traces the path from the current directory through its parent or its
subdirectories and files. As user "raja", I can say ./dir1 since I'm already in /home/raja
---------------------------------------------------------------------------­---------------------------------
27. How to move a directory ?
# mvdir book manual
This moves the book directory under the directory named manual, if the
manual directory exists. Otherwise, the book directory is renamed to manual.
---------------------------------------------------------------------------­---------------------------------
28. What the RAID groups AIX LVM supports?
RAID-0 - Striping
RAID-1 - Mirroring
RAID-10 (or) RAID 0+1 - Mirroring and striping
---------------------------------------------------------------------------­---------------------------------
29. How to read and remove mails from my system mailbox?
At your system command line prompt, enter the mail command:
# mail
If there is no mail in your system mailbox, the system responds with a message:

No mail for YourID
If there is mail in your mailbox, the system displays a listing of the messages in your system mailbox:
# mail
Here Type ? for help.

"/usr/mail/lance": 3 messages 3 new
>N 1 karen Tue Apr 27 16:10 12/321 "Dept Meeting"
N 2 lois Tue Apr 27 16:50 10/350 "System News"
N 3 tom Tue Apr 27 17:00 11/356 "Tools Available"
The current message is always prefixed with a greater-than symbol (>).
Each one-line entry displays the following fields:
status - Indicates the class of the message.
number - Identifies the piece of mail to the mail program.
sender - Identifies the address of the person who sent the mail.
date - Specifies the date the message was received.
size - Defines the number of lines and characters contained in the
message (this includes the header).
subject - Identifies the subject of the message, if it has one.
The status can be any of the following:
- A new message.
P - A message that will be preserved in
---------------------------------------------------------------------------­---------------------------------
30. After logging as an application user (oradba), when I issued "crontab -l" system throwed the below error
0481-103 Cannot open a file in the /var/spool/cron/crontabs directory.
What is the solution?
Here is the solution
a) Create an empty file /var/spool/cron/crontabs/oradba
b) Change the ownership of the file to root.cron
c) Login as oradba and issue "crontab -l" to verify the cron.
---------------------------------------------------------------------------­---------------------------------
31. How to identify the program listening in the given port ?
METHOD I: # lsof –P –n –i :505 (for port 505)
METHOD II:
# netstat -Aan|grep 9404
f100060006952b98 tcp 0 0 *.9404 *.* LIST
EN
f100060006a90b98 tcp 0 0 *.19404 *.* LIST
EN
# rmsock f100060006952b98 tcpcb
The socket 0x6952808 is being held by proccess 753870 (java).
---------------------------------------------------------------------------­---------------------------------
32. How to display non-printable characters in a text file ?
Lets create a file with non-printable characters.
# vi filename.txt
^I^I^I^I$
$
$
$
this is a test$
^I^I^I^I$
~
: set list
Now we will list the file so that non-printable chars are viewed
# cat -vet filename.txt
^I^I^I^I$
$
$
$
this is a test$
^I^I^I^I$
# od -c filename.txt
0000000 \t \t \t \t \n \n \n \n t h i s i s
0000020 a t e s t \n \t \t \t \t \n
0000034
---------------------------------------------------------------------------­---------------------------------
33. How to display specific lines in a text files ?
For illustration purposes, I'm using the cat -n filename to show the line numbers in this script.
# cat -n filename
...
8 for i in $*
9
10 do
11
12 typeset -i16 hex
13 hex=$i
14 print $i equals $hex in hexadecimal
15
16 typeset -i8 oct
17 oct=$i
18 print $i equals $oct in octal
19
20 typeset -i2 bin
21 bin=$i
22 print $i equals $bin in binary
23
24 print
25 done
...
Prints out the for loop without displaying the line numbers
# sed -n 8,25p filename | tee for_loop
---------------------------------------------------------------------------­---------------------------------
34. How to recover the root password in AIX ?
If you forgotten the root password, we can easily recover it but the system requires 2 recycles.
Here is the way I follow
Password recovery is one of the simplest troubleshooting procedure in
AIX. Once you boot from CD, you see a menu with 3 menu items.
In that select the 3rd item
ie., "Start Maintenance Mode for System Recovery" à
"Access a Root Volume Group" ->
"Access this volume group and start a shell".
This will open a shell prompt. The just use "passwd" command for
setting a new password for root.
Thats it. root password has been changed.
Now you can reboot the machine from rootvg hard disk (normally it should be hdisk0)
---------------------------------------------------------------------------­---------------------------------
34. How to find out the (real) memory usage ?
# svmon -G
size inuse free pin virtual
memory 2097152 2097026 126 195637 1237158
pg space 524288 61023
work pers clnt lpage
pin 195404 233 0 0
in use 1189840 906786 400 0
The size and inuse columns of the memory and pgspace output represent real memory and paging space usage respectively.
The size is measured as the number of 4K pages.
Here in this case used memory is
= ((2097026 x 4)/1024)/1024 GB of used memory
---------------------------------------------------------------------------­---------------------------------
35. Here are some of the errors you get when paging space is low.
INIT: Paging space is low!
ksh: cannot fork no swap space
Not enough memory
Fork function failed
fork () system call failed
Unable to fork, too many processes
Fork failure - not enough memory available
Fork function not allowed. Not enough memory available.
---------------------------------------------------------------------------­---------------------------------
36. How is the default paging space size determined ?
It follows the following standard
  • Set paging space to 2 times the amount of RAM
  • Paging space can use no more than 20% of total disk space in the root volume Group
  • Paging space can be no larger than 2 GB

No comments:

Post a Comment