DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.


How to fix BLV of AIX

If a boot logical volume is corrupted (for example, bad blocks on a disk might cause a corrupted BLV), a machine will not boot.

To fix this situation, you must boot your machine in maintenance mode, from a CD or tape. If NIM has been set up for a machine, you can also boot the machine from a NIM master in maintenance mode. By the way, that's what you would do on an SP node if an SP node does not boot.

The boot lists are set using the bootlist command or the System Management Services (SMS) program. Some machines support a normal and service boot list. If your model supports this, you will use a function key during bootup to select the appropriate list. Normally, pressing F5 when you hear the first tones during bootup, will force the machine to check for a bootable CD. More on this later.

After booting from CD, tape or NIM an Installation and Maintenance Menu is shown and you can startup the maintenance mode. We will cover this later in this unit. After accessing the rootvg, you can repair the boot logical volume with the bosboot command. You need to specify the corresponding disk device, for example hdisk0:

# bosboot -ad /dev/hdisk0

It is important that you do a proper shutdown. All changes need to be written from memory to disk.

The bosboot command requires that the boot logical volume hd5 exists. If you ever need to re-create the BLV from scratch - maybe it had been deleted by mistake - the following steps should be followed:
1. Boot your machine in maintenance mode (from CD or tape).
2. Create a new hd5 logical volume: one physical partition in size, must be in rootvg. Specify boot as logical volume type.
3. Run the bosboot command as described.
4. Reboot the server run command

# shutdown -Fr

The following is an example of re-creating boot logical volume (BLV)

1. Boot your machine in maintenance mode (from CD, tape, or NIM).

2. Create a new hd5 logical volume: one physical partition in size, must be in rootvg. Specify boot as logical volume type. if needed, remove hd5 using # rmlv -f hd5

# mklv -y hd5 -t boot -a e rootvg 1

3. Run the bosboot command as described below.

# bosboot -ad /dev/hdisk0


4. Shutdown -Fr.

Mount the Windows NTFS partition in RHEL 5


1) Install the “kernel-module-ntfs” package. Download this package from the below link.


Note: Download both rpm and ko file.

2) Load the ntfs module to the kernel, and confirm with lsmod command

# rpm –ivh kernel-module-ntfs-xxxxx.rpm
# insmod kernel-module-ntfs-xxxxx.ko
# lsmod | grep ntfs

3) Download the “ntfs-3g” and “fuse” packages from the below links.


4) Install the ntfs-3g package by using the below commands

# tar –zxvf ntfs-3g-xxxx.tgz
# cd ntfs-3g-xxxx
# ./configure
# make
# make install


5) Install the fuse package by using the below commands

# tar –zxvf fuse-xxx.tar.gz
# cd fuse-xxx
# ./configure
# make
# make install
# modprobe fuse
6) Now mount the ntfs partition using the below command

# mount –t ntfs-3g /dev/sdb1 /mnt

Note: Here /dev/sdb1 is a windows NTFS partition. Also here usage of fuse version is depend upon the kernel version.
 

Using logger to send file data to syslogd

If you find yourself needing to have the contents of an ASCII text file written to syslog, then consider the use of the logger command. This comes with most Unix distributions and has also been ported to the Windows platform.

There may be times whereby an application or system only logs to a text file and this data needs to be collected into your log management solution. For this example, I’ll assume an ASCII text file with single line entries is the log file and its name is logdata.log. In this scenario, you can utilize the logger command utility to read each line of the file and send it to the local Syslog daemon.

The logger command has some useful command line parameters that can be useful to gain additional control over how the log messages are written to syslog. There are subtle differences between the Unix-based and Windows logger command as seen in the syntax below:

syntax of logger:

logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message …]

Logger makes entries in the system log. It provides a shell command interface to the syslog system log module.

Options:
-i       Log the process id of the logger process with each line.
-s
Log the message to standard error, as well as the system log.
-f file
Log the specified file.
-p pri
Enter the message with the specified priority. The priority may be specified numerically or as a ``facility.level'' pair. For example, ``-p local3.info'' logs the message(s) as info rmational level in the local3 facility. The default is ``user.notice.''
-t tag
Mark every line in the log with the specified tag
-u sock
Write to socket as specified with socket instead of builtin syslog routines.
-d
Use a datagram instead of a stream connection to this socket.
--
End the argument list. This is to allow the message to start with a hyphen (-).
message
Write the message to log; if not specified, and the -f flag is not provided, standard input is logged.

The logger utility exits 0 on success, and >0 if an error occurs.
Valid facility names are: auth, authpriv (for security information of a sensitive nature), cron, daemon, ftp, kern, lpr, mail, news, security (deprecated synonym for auth), syslog, user, uucp, and local0 to local7, inclusive.

An example is shown below:

logger –f  logdata.log –p  local4.alert  Transaction rejected due to invalid data type.

Where the following is true:

logdata.log is the file containing the log messages to be written to syslog.
local4.alert is the facility and severity the log message will have when written to syslog.
“Transaction rejected due to invalid data type.” is the message that is written to syslog.



If you find yourself needing to have the contents of an ASCII text file written to syslog, then consider the use of the logger command. This comes with most Unix distributions and has also been ported to the Windows platform.
There may be times whereby an application or system only logs to a text file and this data needs to be collected into your log management solution. For this example, I’ll assume an ASCII text file with single line entries is the log file and its name is logdata.log. In this scenario, you can utilize the logger command utility to read each line of the file and send it to the local Syslog daemon.
The logger command has some useful command line parameters that can be useful to gain additional control over how the log messages are written to syslog. There are subtle differences between the Unix-based and Windows logger command as seen in the syntax below:
Unix-based logger:
logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message …]
Windows-based logger:
logger [-?] [-is] [-f file] [-p pri] [-t tag] [-a port] [-l loghost] [-m udp|tcp|3195raw] [message ..]
An example in Unix is shown below:
logger –f logdata.log –p local4.alert Transaction rejected due to invalid data type.
Where the following is true:
logdata.log is the file containing the log messages to be written to syslog.
local4.alert is the facility and severity the log message will have when written to syslog.
“Transaction rejected due to invalid data type.” is the message that is written to syslog.
- See more at: http://blog.logrhythm.com/uncategorized/using-logger-to-send-file-data-to-syslogd/#sthash.vzh3d8eE.dpuf

work with sendmail in AIX

Sendmail has been included with the AIX operating system for many years now.
Despite its reputation for being difficult to administer, it is very powerful and can perform some interesting tricks. It's helped me overcome some challenges over the years.
This article shares two interesting tricks that I discovered with Sendmail on AIX.
 

To start the Sendmail daemon, use the startsrc command. For example:

# startsrc -s sendmail -a "-bd -q30m"

The –s flag specifies the subsystem to start, and the –a flag instructs startsrc to execute the subsystem with the specified arguments.
The -bd flag starts Sendmail as a daemon (running in the background) as a Simple Mail Transfer Protocol (SMTP) mail router. The –q flag specifies the interval at which the Sendmail daemon processes saved messages in the mail queue. In this example, Sendmail will process the mail queue every 30 minutes.

To start the Sendmail daemon automatically on a reboot, uncomment the following line in the /etc/rc.tcpip file:
# vi /etc/rc.tcpip
start /usr/lib/sendmail "$src_running" "-bd -q${qpi}"

Execute the following command to display the status of the Sendmail daemon:
# lssrc -s sendmail

To stop Sendmail, use stopsrc:
# stopsrc -s sendmail

The Sendmail configuration file is located in the /etc/mail/sendmail.cf file, and the Sendmail mail alias file is located in /etc/mail/aliases.
If you add an alias to the /etc/mail/aliases file, remember to rebuild the aliases database and run the sendmail command with the -bi flag or the /usr/sbin/newaliases command. This forces the Sendmail daemon to re-read the aliases file.
# sendmail -bi

To add a mail relay server (smart host) to the Sendmail configuration file, edit the /etc/mail/sendmail.cf file, modify the DS line, and refresh the daemon:
# vi /etc/mail/sendmail.cf
DSsmtpgateway.xyz.com.au
# refresh -s sendmail

To log Sendmail activity, place the following entry in the /etc/syslog.conf file, create the log file, and refresh the syslog daemon:
# grep mail /etc/syslog.conf
mail.debug  /var/log/maillog rotate time 7d files 4 compress
# touch /var/log/maillog
# refresh –s syslogd

What is SGID and how to set SGID in Linux?

What is SGID?


SGID (Set Group ID up on execution) is a special type of file permissions given to a file/folder. Normally in Linux/Unix when a program runs, it inherits access permissions from the logged in user. SGID is defined as giving temporary permissions to a user to run a program/file with the permissions of the file group permissions to become member of that group to execute the file. In simple words users will get file Group’s permissions when executing a Folder/file/program/command.
SGID is similar to SUID. The difference between both is that SUID assumes owner of the file permissions and SGID assumes group’s permissions when executing a file instead of logged in user inherit permissions.

 

Learn SGID with examples:


Example: Linux Group quota implementation
 
When implementing Linux Group quota for group of people SGID plays an important role in checking the quota timer. SGID bit set on folder is used to change their inherit permissions to group’s permissions to make it as single user who is dumping data. So that group members whoever dumps the data the data will be written with group permissions and in turn quota will be reduced centrally for all the users. For clear understanding of this you have to implement group quota from the above link. Without implementation of SGID the quota will not be effective.

How can I setup SGID for a file?


SGID can be set in two ways

1) Symbolic way (s)

2) Numerical/octal way (2, SGID bit as value 2)
 
Use chmod command to set SGID on file: file1.txt

Symbolic way:
 
chmod g+s file1.txt
 
Let me explain above command we are setting SGID(+s) to group who owns this file.

Numerical way:
 
chmod 2750 file1.txt
 
Here in 2750, 2 indicates SGID bitset, 7 for full permissions for owner, 5 for read and execute permissions for group, and no permissions for others.
 
How can I check if a file is set with SGID bit or not?
 
Use ls –l to check if the x in group permissions field is replaced by s or S
For example: file1.txt listing before and after SGID set

Before SGID set:
ls -l

total 8

-rwxr--r-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt
 
After SGID set:
ls -l

total 8

-rwxr-sr-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt 
 
Some FAQ’s related to SGID:

 
Where is SUID used?
 
1) When implementing Linux group disk quota.
I am seeing “S” ie Capital s in the file permissions, what’s that?
After setting SUID or SGID to a file/folder if you see ‘S’ in the file permission area that indicates that the file/folder does not have executable permissions for that user or group on that particular file/folder.
chmod g+s file1.txt
output:
-rwxrwSr-x 1 surendra surendra 0 Dec 27 11:24 file1.txt



so if you want executable permissions too, apply executable permissions to the file.
chmod g+x file1.txt
output:
-rwxrwsr-x 1 surendra surendra 0 Dec 5 11:24 file1.txt




How can I find all the SGID set files in Linux/Unix.
 
find / -perm +2000
The above find command will check all the files which is set with SGID bit(2000).


Can I set SGID for folders?
Yes, you can if it’s required (you should remember one thing, that Linux treats everything as a file)
How can I remove SGID bit on a file/folder?

chmod g-s file1.txt

What is SUID and how to set SUID in Linux/Unix?


What is SUID and how to set it in Linux?


SUID (Set owner User ID up on execution) is a special type of file permissions given to a file. Normally in Linux/Unix when a program runs, it inherits access permissions from the logged in user. SUID is defined as giving temporary permissions to a user to run a program/file with the permissions of the file owner rather that the user who is running it. In simple words users will get file owner’s permissions as well as owner UID and GID when executing a file/program/command.

The above sentence is bit tricky and should be explained in-depth with examples.

Learn SUID with examples:

 

Example1: passwd command


When we try to change our password we will use passwd command which is owned by root. This passwd command file will try to edit some system config files such as /etc/passwd, /etc/shadow etc when we try to change our password. Some of these files cannot be opened or viewed by normal user only root user will have permissions. So if we try to remove SUID and give full permissions to this passwd command file it cannot open other files such as /etc/shadow file to update the changes and we will get permission denied error or some other error when tried to execute passwd command. So passwd command is set with SUID to give root user permissions to normal user so that it can update /etc/shadow and other files.

Example2: ping command



Similarly if we take ping command, when we have to execute this command internally it should open socket files and open ports in order to send IP packets and receive IP packets to remote server. Normal users don’t have permissions to open socket files and open ports. So SUID bit is set on this file/command so that whoever executes this will get owner (Root user’s) permissions to them when executing this command. So when this command start executing it will inherit root user permissions to this normal user and opens require socket files and ports.

Example3: crontab and at command.


When scheduling the jobs by using crontab or at command it is obvious to edit some of the crontab related configuration files located in /etc which are not writable for normal users. So crontab/at commands are set with SUID in-order to write some data.

How can I setup SUID for a file?

 

SUID can be set in two ways

1) Symbolic way(s, Stands for Set) 
2) Numerical/octal way(4)
 
Use chmod command to set SUID on file: file1.txt

Symbolic way:

chmod u+s file1.txt
Here owner permission execute bit is set to SUID with +s

Numerical way:

chmod 4750 file1.txt
 
Here in 4750, 4 indicates SUID bit set, 7 for full permissions for owner, 5 for write and execute permissions for group, and no permissions for others.

How can I check if a file is set with SUID bit or not?

Use ls –l to check if the x in owner permissions field is replaced by s or S

For example: file1.txt listing before and after SUID set

Before SUID set:

ls -l
total 8

-rwxr--r-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt
 
After SUID set:

ls -l
total 8

-rwsr--r-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt

 

Some FAQ’s related to SUID:

 

A) Where is SUID used?

1) Where root login is required to execute some commands/programs/scripts.
2) Where you don’t want to give credentials of a particular user and but want to run some programs as the owner.
3) Where you don’t want to use SUDO command but want to give execute permission for a file/script etc.

B) I am seeing “S” I.e. Capital “s” in the file permissions, what’s that?

After setting SUID to a file/folder if you see ‘S’ in the file permission area that indicates that the file/folder does not have executable permissions for that user on that particular file/folder.
For example see below example

chmod u+s file1.txt
ls -l
-rwSrwxr-x 1 surendra surendra 0 Dec 27 11:24 file1.txt
 
If you want to convert this S to s then add executable permissions to this file as show below
chmod u+x file1.txt
ls -l
-rwsrwxr-x 1 surendra surendra 0 Dec 5 11:24 file1.txt
you should see a smaller ‘s’ in the executable permission position now.


SUID with execute permissions:

SUID_Linux


SUID with out execute permissions:

SUID_Linux_without_execute_permissions

C) How can I find all the SUID set files in Linux/Unix.

find / -perm +4000
The above find command will check all the files which is set with SUID bit(4000).

D) Can I set SUID for folders?

Yes, you can if its required(you should remember one thing, that Linux treats everything as a file)

E) What is SUID numerical value?
It has the value 4

What is a sticky Bit and how to set it in Linux?

What is Sticky Bit?

Sticky Bit is mainly used on folders in order to avoid deletion of a folder and its content by other users though they having write permissions on the folder contents. If Sticky bit is enabled on a folder, the folder contents are deleted by only owner who created them and the root user. No one else can delete other users data in this folder(Where sticky bit is set). This is a security measure to avoid deletion of critical folders and their content(sub-folders and files), though other users have full permissions.

Learn Sticky Bit with examples:

 

Example: Create a project(A folder) where people will try to dump files for sharing, but they should not delete the files created by other users.
  
How can I setup Sticky Bit for a Folder?

Sticky Bit can be set in two ways
  1. Symbolic way (t,represents sticky bit)
  2. Numerical/octal way (1, Sticky Bit bit as value 1)
Use chmod command to set Sticky Bit on Folder: /opt/dump/

Symbolic way:

chmod o+t /opt/dump/
or
chmod +t /opt/dump/

Let me explain above command, We are setting Sticky Bit(+t) to folder /opt/dump by using chmod command.

Numerical way:

chmod 1757 /opt/dump/

Here in 1757, 1 indicates Sticky Bit set, 7 for full permissions for owner, 5 for read and execute permissions for group, and full permissions for others.

Checking if a folder is set with Sticky Bit or not?

Use ls –l to check if the x in others permissions field is replaced by t or T
For example: /opt/dump/ listing before and after Sticky Bit set

Before Sticky Bit set:
ls -l
total 8
-rwxr-xrwx 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

After Sticky Bit set:
ls -l
total 8
-rwxr-xrwt 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

Some FAQ’s related to Sticky Bit:

 

Now sticky bit is set, lets check if user “temp” can delete this folder which is created xyz user.

$ rm -rf /opt/dump
rm: cannot remove `/opt/dump’: Operation not permitted

$ ls -l /opt
total 8
drwxrwxrwt 4 xyz xyzgroup 4096 2012-01-01 17:37 dump
$


if you observe other user is unable to delete the folder /opt/dump. And now content in this folder such as files and folders can be deleted by their respective owners who created them. No one can delete other users data in this folder though they have full permissions.I am seeing “T” ie Capital s in the file permissions, what’s that?
After setting Sticky Bit to a file/folder, if you see ‘T’ in the file permission area that indicates the file/folder does not have executable permissions for all users on that particular file/folder.

Sticky bit without Executable permissions:




so if you want executable permissions, Apply executable permissions to the file.

chmod o+x /opt/dump/
ls -l command output:
-rwxr-xrwt 1 xyz xyzgroup 0 Dec 5 11:24 /opt/dump/

Sticky bit with Executable permissions:


sticky bit unix, unix sticky bit, suid, linux sticky bit, sticky bit in unix, sticky bit aix, sticky bit chmod, sticky bits, sticky bit linux, suid sgid sticky bit, set sticky bit, stickybit, sticky bit permission, setting sticky bit, solaris sticky bit, sticky bit solaris, sticky bit directory, remove sticky bit, ubuntu sticky bit, sticky bit t, aix sticky bit, sticky bit load balancer, directory sticky bit, umask


you should see a smaller ‘t’ in the executable permission position.
How can I find all the Sticky Bit set files in Linux/Unix.

find / -perm +1000
The above find command will check all the files which is set with Sticky Bit bit(1000).

Can I set Sticky Bit for files?
Yes, but most of the time it’s not required.

How can I remove Sticky Bit bit on a file/folder?
chmod o-t /opt/dump/

Rotating Log Files

This script moves on log files listed on the command line. It keeps all but the most recent one
compressed, and removes the last one once there are more than CYCLES of them. For example,
CYCLES=3 ; rotate messages Would have the following effects.

messages --> messages.1
messages.1 --> messages.2.gz
messages.2.gz --> messages.3.gz
messages.3.gz --> removed

script :


#!/bin/sh
# Rotate a log file and keep N copies
# Mostly stolen from inn
CYCLES=${CYCLES-5}
COMPRESS=/usr/local/bin/gzip
Z=.gz
for F in $* ; do
## Compress yesterday’s .1
test -f ${F}.1 \
&& ${COMPRESS} <${F}.1 >${F}.1${Z} \
&& rm -f ${F}.1 \
&& chmod 0440 ${F}.1${Z}
## Do rotation.
EXT=${CYCLES}
rm -f ${F}.${CYCLES}${Z}
while [ ${EXT} -gt 0 ] ; do
NEXT=${EXT}
EXT=‘expr ${EXT} - 1‘
test -f ${F].${EXT}${Z} \
&& rm -f ${F}.${NEXT}${Z} \
&& mv ${F}.${EXT}${Z} ${F}.${NEXT}${Z}
done
mv ${F} ${F}.1
done


Different RUN levels in Linux,Solaris and AIX

RedHat Linux - Run Levels 

 

0: Halt
1: Single user mode
2: Multiuser, without NFS
3: Full multiuser mode
4: Unused
5: X11
6: Reboot
 

Solaris - Run Level 

 

S: Single user state (useful for recovery)
0: Access Sun Firmware ( ok> prompt)
1: System administrator mode
2: Multi-user w/o NFS
3: Multi-user with NFS ( default run level)
4: Unused
5: Completely shutdown the host (like performing a power-off @ OBP) [ thanks to Marco ]
6: Reboot but depend upon initdefault entry in /etc/inittab

AIX - Run Levels


0-1: Reserved for future use
2: Multiuser mode with NFS resources shared (default run level)
3-9: Defined according to the user's preferences
m,M,s,S: Single-user mode (maintenance level)
a,b,c: Starts processes assigned to the new run levels while leaving the existing processes at the current level running
Q,q: init command to reexamine the /etc/inittab file

Command to see Run level:-

$ who -r
Output:
. run-level 3 Mar 3 14:04 3 0 S

Solaris/Linux changing runlevels after bootup 

 

You need to use init command, for example change runlevel to 2.
# /sbin/init 2
Solaris changing the default runlevel
An entry with initdefault (in /etc/inittab file) is scanned only when init is initially invoked. init uses this entry to determine which run level to enter initially.
Open /etc/inittab file:
# vi /etc/inittab
Find out this entry:
is:3:initdefault: Change is:3 to number you want, don't use S, 0, 6 ;). Save file.
 
 

Runs previous command replacing the typo

when we run a command with a typo, we can correct the typo and re-run the command by the following command.

^wrong^right

Here are the examples:

The man command is wrongly typed as many
[root@test /]# many head
-bash: many: command not found


The y is replaced with empty character.
[root@test /]# ^y
man head

--------------------------------------------------------------
Here man is typed as men

[root@test /]# men head
-bash: men: command not found
the letter e is replaced with a and then the command executes.
[root@test /]# ^e^a
man head


Pushd and popd in bash

Push your present working directory to a stack that you can pop later

If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.

cd /home/complicated/path/.I/dont/want/to/forget

pushd /tmp

cd thing/in/tmp

popd (returns you to /home/complicated/path/.I/dont/want/to/forget)


awk one-liner Tips

Print column1, column5 and column7 of a data file or output of any columns list

$awk ‘{print $1, $5, $7}’ data_file

$cat file_name |awk ‘{print $1 $5 $7}’

$ls –al |awk ‘{print $1, $5, $7}’
-- Prints file_permissions,size and date

Syntax of running an awk program

Awk ‘program’ input file(s)

List all files names whose file size greater than zero.

$ls –al |awk ‘$5 > 0 {print $9}’

List all files whose file size equal to 512bytes.

$ls –al |awk ‘$5 == 512 {print $9}’

print all lines

$awk ‘{print }’ file_name

$awk ‘{print 0}’ file_name


Number of lines in a file

$awk ‘ END {print NR}’ file_name

Number of columns in each row of a file

$awk ‘ {print NF’} file_name

Sort the output of file and eliminate duplicate rows

$awk ‘{print $1, $5, $7}’ |sort –u

List all file names whose file size is greater than 512bytes and owner is "oracle"

$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’

List all file names whose owner could be either "oracle" or "root"

$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’

list all the files whose owner is not "oracle

$ls –al |awk ‘$3 != "oracle" {print $9}’

List all lines which has atlease one or more characters

$awk ‘NF > 0 {print }’ file_name

List all lines longer that 50 characters

$awk ‘length($0) > 50 ‘{print }’ file_name

List first two columns

$awk ‘{print $1, $2}’ file_name
Swap first two columns of a file and print

$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name

Replace first column as "ORACLE" in a data file

$awk ‘{$1 = "ORACLE"; print }’ data_file
Remove first column values in a data file

$awk ‘{$1 =""; print }’ data_file

Calculate total size of a directory in Mb

$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Calculate total size of a directory including sub directories in Mb

$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Find largest file in a directory including sub directories

$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1

How to check if I am running a uniprocessor kernel or a multiprocessor kernel?

/unix is a symbolic link to the booted kernel. To find out what kernel mode is running, enter ls -l /unix and see what file /unix it links to.
The following are the three possible outputs from the ls -l /unix command and their  corresponding kernels:

/unix -> /usr/lib/boot/unix_up                                                            # 32 bit uniprocessor kernel
/unix -> /usr/lib/boot/unix_mp                                                           # 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64                                                            # 64 bit multiprocessor kernel



Memory utilisation of processes in AIX

For memory information, we use the command svmon.
svmon shows the total usage of physical and paging memory.

Command to display top ten processes and users
svmon -P -v -t 10 | more

Displaying top CPU_consuming processes:
ps aux | head -1; ps aux | sort -rn +2
Displaying top memory-consuming processes:
ps aux | head -1; ps aux | sort -rn +3 | head

Displaying process in order of priority:
ps -eakl | sort -n +6 | head

Displaying the process in order of time
ps vx | head -1;ps vx | grep -v PID | sort -rn +3

Displaying the process in order of real memory use
ps vx | head -1; ps vx | grep -v PID | sort -rn +6

Displaying the process in order of I/O
ps vx | head -1; ps vx | grep -v PID | sort -rn +4


Execute a command without saving it in the history

Prepending one or more spaces to your command won't be saved in history.
It i very useful for hiding your commands which consists of passwords on the commandline.
This is tested in bash shell and works successfully.

Example :
$ echo this goes to history
this goes to history

$ echo this wont go to history
this wont go to history

$ history
1 echo this goes to history
2 history

The manual page of "bash" shows as follows:
 
 HISTCONTROL
         A  colon-separated  list of values controlling how commands are
         saved on the history list.  If  the  list  of  values  includes
         ignorespace,  lines  which begin with a space character are not
         saved in the history list.  A value of ignoredups causes  lines
         matching  the  previous history entry to not be saved.  A value
         of ignoreboth is shorthand for ignorespace and  ignoredups.   A
         value  of erasedups causes all previous lines matching the cur
         rent line to be removed from the history list before that  line
         is  saved.   Any  value  not  in the above list is ignored.  If
         HISTCONTROL is unset, or does not include a  valid  value,  all
         lines  read  by the shell parser are saved on the history list,
         subject to the value of HISTIGNORE.  The second and  subsequent
         lines  of a multi-line compound command are not tested, and are
         added to the history regardless of the value of HISTCONTROL. 
Exit without saving history

kill -9 $$

this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged

... $ ( or ${$} ) is the pid of the current bash instance

this also works perfectly in shells that don't have $ if you do something like

kill -9 `readlink /proc/self`
 

Single command to find out RAM(memory) size in Linux

You can use the command cat /proc/meminfo to get the memory details in the linux operating system.
But this gives much more information of memory.
If you need just the memory size , use the below command to get that.


cat /proc/meminfo | awk 'match($1,"MemTotal") == 1 {print $2}'

This gives the memory size in kilobytes(kb).
But I don't know if the format of /proc/meminfo varies among distribution.

 

Display Number of Processors on Linux

If you’ve just upgraded your Linux box, or you are wondering how many processors a remote server has, there’s a quick command you can use to display the number of processors.

On Linux, /proc/cpuinfo contains all of the processor information for all current processors in your computer. This will include the speed, the amount of on-chip cache, processor type, and how many cores.

Here’s the command:
cat /proc/cpuinfo | grep processor | wc -l
The command just looks in the /proc/cpuinfo file, pulls out the number of lines containing the word “processor” and passes them into wc (word count), which returns a count of the CPUs in the system.

uudecode Command


The uudecode utility reads a file or standard input if no file is specified, that includes data created by the uuencode utility. The uudecode utility scans the input file, searching for data compatible with the format specified in uuencode and attempts to create or overwrite the file described by the data. The pathname, file access permission bits and contents for the file to be produced are all contained in that data. The mode bits of the created file will be set from the file access permission bits contained in the data; that is, other attributes of the mode, including the file mode creation mask, will not affect the file being produced.

If the pathname of the file to be produced exists, and the user does not have write permission on that file, uudecode will terminate with an error. If the pathname of the file to be produced exists, and the user has write permission on that file, the existing file will be overwritten.

If the input data was produced by uuencode on a system with a different number of bits per byte than on the target system, the results of uudecode are unspecified.

Purpose

Decodes a binary file that was used for transmission using electronic mail.

Syntax

uudecode [ -o OutputFile ] [ InFile ]

Description

The uudecode command reads an encoded file, strips off leading and trailing lines added by mailers, and recreates the original file with the specified mode and name. Decoding a file causes the result to be automatically saved to a file. The file name is identical to the remote file argument originally supplied to the uuencode command unless an output file name is specified with the -o flag.

Flags

-o OutputFile Specifies the output file name that will be used instead of any pathname contained in the input data. You can direct the output of uudecode to standard output by specifying /dev/stdout as the OutputFile.

Parameters
InFile Specifies the name of the file to decode.

Example

To decode the file /tmp/con on a local system that was encoded with the follwing command:

uuencode /usr/lib/boot/unix pigmy.goat > /tmp/con

enter: uudecode /tmp/con

The file pigmy.goat will be identical to the originally encoded file /usr/lib/boot/unix.

uuencode Command


The uuencode utility writes an encoded version of the named input file, or standard input if no file is specified, to standard output. The output is encoded using the algorithm described in the STDOUT section and includes the file access permission bits (in chmod octal or symbolic notation) of the input file and the decode_pathname, for re-creation of the file on another system that conforms to this specification
 
Purpose
Encodes a binary file for transmission using electronic mail.

Syntax
 
uuencode [ -m ] [ SourceFile ] OutputFile

Description

The uuencode command converts a binary file to ASCII data. This is useful before using BNU (or uucp) mail to send the file to a remote system. The uudecode command converts ASCII data created by the uuencode command back into its original binary form.

The uuencode command takes the named SourceFile (default standard input) and produces an encoded version on the standard output. The encoding uses only printable ASCII characters, and includes the mode of the file and the OutputFile filename used for recreation of the binary image on the remote system.

Use the uudecode command to decode the file.

Flags

-m   Encode the output using the MIME Base64 algorithm. If -m is not specified, the old uuencode algorithm will be used.

Parameters 

OutputFile Specifies the name of the decoded file. You can direct the output of the uuencode command to standard output by specifying /dev/stdout as the OutputFile.
SourceFile Specifies the name of the binary file to convert. Default is standard input.

Examples

To encode the file unix on the local system and mail it to the user jsmith on another system called mysys, enter: uuencode unix unix | mail jsmith@mysys


To encode the file /usr/lib/boot/unix on your local system with the name pigmy.goat in the file /tmp/con , enter: uuencode /usr/lib/boot/unix pigmy.goat > /tmp/con


SUDO in UNIX

Sudo is a standard way to give users some administrative rights without giving out the root
password. Sudo is very useful in a multi user environment with a mix of server and
workstations. Simply call the command with sudo:

# sudo /etc/init.d/dhcpd restart                                   # Run the rc script as root
# sudo -u sysadmin whoami                                       # Run cmd as an other user

 Configuration :

Sudo is configured in /etc/sudoers and must only be edited with visudo. The basic syntax is
(the lists are comma separated):

user hosts = (runas) commands                                   # In /etc/sudoers
users one or more users or %group (like %wheel) to gain the rights
hosts list of hosts (or ALL)
runas list of users (or ALL) that the command rule can be run as. It is enclosed in ( )!
commands list of commands (or ALL) that will be run as root or as (runas)
Additionally those keywords can be defined as alias, they are called User_Alias, Host_Alias,
Runas_Alias and Cmnd_Alias. This is useful for larger setups.

Here a sudoers example:

# cat /etc/sudoers

# Host aliases are subnets or hostnames.
Host_Alias DMZ = 212.118.81.40/28
Host_Alias DESKTOP = work1, work2

# User aliases are a list of users which can have the same rights

User_Alias ADMINS = colin, luca, admin
User_Alias DEVEL = joe, jack, julia
Runas_Alias DBA = oracle,pgsql

# Command aliases define the full path of a list of commands
Cmnd_Alias SYSTEM = /sbin/reboot,/usr/bin/kill,/sbin/halt,/sbin/shutdown,/etc/init.d/
Cmnd_Alias PW = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root           # Not root pwd!
Cmnd_Alias DEBUG = /usr/sbin/tcpdump,/usr/bin/wireshark,/usr/bin/nmap

# The actual rules
root,ADMINS ALL = (ALL) NOPASSWD: ALL             # ADMINS can do anything w/o a password.
DEVEL DESKTOP = (ALL) NOPASSWD: ALL             # Developers have full right on desktops
DEVEL DMZ = (ALL) NOPASSWD: DEBUG                 # Developers can debug the DMZ servers.

# User sysadmin can mess around in the DMZ servers with some commands.
sysadmin DMZ = (ALL) NOPASSWD: SYSTEM,PW,DEBUG
sysadmin ALL,!DMZ = (ALL) NOPASSWD: ALL            # Can do anything outside the DMZ.
%dba ALL = (DBA) ALL # Group dba can run as database user.
# anyone can mount/unmount a cd-rom on the desktop machines
ALL DESKTOP = NOPASSWD: /sbin/mount /cdrom,/sbin/umount /cdrom

Difference between /etc/hosts and /etc/resolv.conf

/etc/resolv.conf specifies the nameservers for resolver lookups, where it will actual use the DNS protocol for resolving the hostnames.
Typically the /etc/hosts file is used for administrative purposes such as backend and internal functions, which is substantially more isolated in scope, as only the local server will reference it it.

/etc/nsswitch.conf
specifies the lookup order with the hosts entry.

If this does not answer your question, please clarify further.

Look at the following manpages:

/etc/resolv.conf
specifies nameservers in order of search preference.
/etc/hosts overrides all nameservers by mapping urls/shortnames to IPs.


Extracting snap.pax.Z file - AIX

 For basic dump analysis, this article is mostly interested in a dump image. Here, we cover how to extract the appropriate files from the snap package and then explain a methodical approach to examine the dump, and find the fundamental reason for a system crash. The dump file and the UNIX® file are in the dump subdirectory of the snap package.

Though we are primarily focused on the dump image, it is important to note that snap can provide you with useful information when used with appropriate options. Additional information is found in the General and Kernel subsections of the article.

General

This general directory includes information about the system runtime environment, for example:

  •     Copy of ODM data.
  •     All environment variables (e.g., PATH and TZ).
  •     Date and time the data was collected.
  •     Amount of real memory on the system (bootinfo -r).
  •     Listing of all defined paging spaces.
  •     Listing of all installed filesets and their levels.
  •     Listing of all installed APARs.
  •     Device attributes (lsattr -El).
  •     System VPD information (lscfg -pv).
  •     Status of last dump (sysdumpdev -L).

Kernel

The kernel subdirectory contains useful kernel information (Process and memory data).

  •     Date and time the data was collected
  •     Vmstat output
  •     VMM tunable information (vmo -L).
  •     Scheduling tunable information (schedo -L).
  •     I/O related tunable iformation (ioo -L).
  •     Environment variables.
  •     SRC information (lssrc -a).
  •     Process information (ps -ef and ps -leaf).
  •     Checksum of device drivers and methods.

Extracting the snap package

The pax command is used to extract files from the snap package.

    To view the contents of a snap package, type:

    # zcat snap.pax.Z | pax -v


    To extract the entire contents of a package, type:

     # zcat snap.pax.Z | pax -r


    To extract just the dump, general, and kernel subdirectories, type:

     #uncompress snap.pax.Z
     #zcat snap.pax.Z | pax -r ./dump ./general ./kernel

Open Source with AIX

AIX has a large range of Open Source tools, and applications already ported and packaged ready for you to install. This makes it far easier and quick to get Open Source tools and applications working and useful on AIX. All the big popular Open Source stuff is available. My favourites that are in the first URL below are:

  • Apache - web server the one that runs the web
  • emacs - editor and so much more
  • ethereal - network monitoring by packets, protocol, contents
  • Ganglia - cluster performance monitoring and graphing
  • GNC GCC - compiler collection particularly C and C++
  • gimp - image manipulation
  • Gnome - desktop
  • KDE - desktop
  • gzip - file compression utility
  • MySQL - the database
  • PHP - scripting, good for web servers
  • rdist - file distribution
  • Samba - Windows filesystem and printing and much more
  • rxvt - colour xterm
  • squid - proxy server
  • vim - improved vi editor for colourised syntax highlighing
  • VNC - Virtual Network Computing X windows on any machine (even Windows!!)
  • wget - checking and copying websites

Well, your list might be different but there are hundreds of them available. You can, of course, download the original source code and compile it yourself but this means you will need the compilers (most use the GNC compilers), some programing skills and time to read up on the options and build process. then you need to perform some testing to prove it is all working.
Hint: I always compile with the latest GNU compilers to avoid problems.

Installation specific commands in AIX

Below are the commands which are related to the installation in aix.


lslpp -l To see the details of installed file sets


lslpp -ha bos.net.* To list the installation history of all file set in bos.net packages


lslpp -f bos.rte To list the files in the bos.rte package


lslpp -w /etc/hosts To list the file set which contain /etc/hosts file (parent fileset)


lslpp -p bos.net.nfs.server To list the pre requisites for bos.net.nfs.server file set 


lslpp -d To show dependancies of fileset
          
installp -L -d /dev/rmt0.1 To list the installable products on the device rmt0


installp -aX -d /dev/rmt0.1 bos.net To install all filesets within bos.net and expands file system if it requires


installp -u bos.net To remove bos.net


installp -r To reject the applied software


installp -c -f To commit the applied fileset


installp -C To cleanup an incomplete installation


lppchk -c To check the fileset items and verifies that the checksum and filesize are consistent with SWVPD


lppchk -v verify that all filesets have required requisites and are completely installed


instfix -k IX9999 -d /dev/rmt0.1 To install the file set associated with fix IX9999 from rmt0


instfix -ik IX9999 To verify fix IX9999 installed


Paging space commands in AIX

Below are the commands related to the paging space in AIX.


lsps -a To list out all paging spaces


lsps hd6 To display the details of the paging space hd6


chps -a y paging00 To turn on the paging space paging00 on next reboot


chps -a n paging00 To turn off the paging space paging00 on next reboot


chps -s4 paging00 To increase the size of the paging space in 4 LP blocks


mkps -a -n -s4 newvg To create a paging space on VG newvg of 4 LP size (-s4) and activate it immediately (-n) and activate it at every restarts


rmps paging00 To remove the paging space paging00


swapon -a To invoke all entries in /etc/swapspaces file


swapon /dev/paging00 To make available swap space paging00


swapoff /dev/paging00 To disable swap space paging00



Disable telnet in AIX

The procedure to disable telnet in AIX is as follows:

#vi /etc/inetd.conf

comment out telnet from this file (#telnet ... ... .. )

save it and

#refresh -s inetd

Then telnet session will be disabled in that server from now

Filesystem commands in AIX

lsfs Lists all filesystems in the /etc/filesystems entry


lsfs -a To list all filesystems (default)


lsfs -q List all filesystems with detailed info (shows size of FS and LV in it. so we can check whether size of LV=size os FS)


lsfs -l Specify the output in list format


lsfs -c Specify the output in column format


lsfs -v jfs Lists all jfs filesystems


chfs -a size=24576 /test Change size of FS /test to 24576(blocks)x 512 bytes  (12 MB)


chfs -a size=+24576 /test Add 24576(blocks)x512 byte  to FS /test


chfs -a size=+64M /test Add 64 MB to /test


chfs -a size=10G /test fix size of the FS /test to 10 GB


chfs -m /test /new Change the mount point from /test to /new


chfs -A /test To auto mount the filesystem test


chfs -d account /test Remove account attribute of /test.(from /etc/filesystems file)


chfs -a splitcopy=/backup -a copy=2 /oracle This will mount the 2nd copy of mirrored filesystem oracle to /backup in read-only mode for backup purpose


crfs -v jfs2 -g newvg -a size=100M -m /test Creates FS /test of type jfs in VG newvg of size 100 MB with default LV.


crfs -v jfs -d /dev/lv00 -m /test Create FS /test of type jfs on device /dev/lv00


rmfs /test Deletes FS /test and associated LV


rmfs -r /test Deletes FS /test its mount point and associated LV


defragfs /test To defragment the file system /test


defragfs -q /test Display the current defrag status of the file system


fsck -y n /dev/lv00 To check the filesystem associated to /dev/lv00 assuming response "yes"


fsck -p /dev/lv00 To restore superblock from backup superblock




Recreate BOOT LOGICAL VOLUME (BLV) in AIX



If a Boot Logical volume (BLV) is corrupted, a machine will not boot.
(Eg:bad block in a disk might cause a corrupted BLV)

To fix this situation, You must boot your machine in maintenance mode, from a CD or Tape. If a NIM has been setup for a machine, you can also boot the machine from a NIM master in maintenance mode.

The bootlists are set using the bootlist command or through the System Management Services Progam (SMS). pressing F1 will go to SMS Mode.

then change the bootlist for service(maintenance) mode as 1st device to CD ROM.

#bootlist -m service cd0 hdisk0 hdisk1

then start maintenance mode for system recovery,

Access rootvg,

access this volume group to start a shell,

then recreate BLV using bosboot command.

#bosboot -ad /dev/hdisk0

it's important that you do a proper shutdown, All changes need to be written from memory to disk.

#shutdown -Fr

Imp: bosboot command requires that boot logical volume hd5 exists. If you wan create a BLV ( may be it had been deleted by mistake ), do the following,

1. Boot your machine in maintenance mode,
2. Create a new hd5 logical volume, one PP size, must be in rootvg,specify boot as logical volume type,

#mklv -y hd5 -t boot rootvg 1

3. Then run bosboot command as described.

If you have an HMC, then at the time of booting select boot as SMS in the menu