November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Aix commands

Commands

CUT:

lspv | cut -c 6-7 lists the hdisks numbers (cuts the 6th and 7tn character (disk nubers))
dlnkmgr view -drv | grep -w 00000 | awk ‘{print $4}’ | cut -d . -f 3

——————————————————————————–

EXPR: integer arithmetic

\* multiplication (\ is needed to tell * is not a special character)
/ division
% remainder
+ addition
– substraction

expr \( 6 + 4 \) / 2 5

——————————————————————————–

FIND: recursively searches the directory tree

find / -xdev -type f -name “cor*” -size +10000c -exec ls -l {} \;

/ where to find
-xdev looks only in the given fs
-type f what type to look for (f: file, d: direcory)
-name “cor*” name to look for
-size +10000c search for the given size (+10000c : greater than 10000 character (larger then 10kbyte))
-size +2 search for greater than 1kbyte (bloxk size is 512 byte, that’s why +2 is given)
-exec ls -l {} \; what command to execute
({}: it represents each findings and \; is needed at the end of line)
e.g. find /home -xdev -name “*.old” -exec rm {} \;
-mtime -1 file modifocation date is less then 1 day (+1 means older than 1 day)

find . -name ‘*.ksh’ -ok rm {} \; this will ask if the command (rm) should be executed or not (much safer if find is not perfect)
find /etc/rc.d -ls it lists the files and dirs in the given dir
find /tmp/bb -exec awk ‘/func/ {print FILENAME}’ {} \; it will check in /tmp/bb if any files contains the word “func” and list those

——————————————————————————–

GREP: (Global Regular Expression Parser) The grep command searches for the pattern.

grep -i ignore case (small letter or capital)
grep -c displays only a count of matching lines
grep -n shows line number at the beginning of the matching line
grep -v invert the sense of matching, to select non-matching lines
grep -w selects only whole words
grep -l lists the name of the files (once) which contain matching line (grep -l paging00 *)

ps -ef | egrep ‘ssh|aix’ select lines with ssh and aix
errpt -a|grep -A1 ‘NAME’ selects lines with NAME and shows 1 line after that (A: after, B: before)

——————————————————————————–

HEAD, TAIL:

head filename displays first 10 lines of the file
head -50 filename displays first 50 lines

tail filename displays last 10 lines of the file
tail -50 filename displays last 50 lines
tail +15 filename displays the file starting from the 15th line
tail -f filename used when we are monitoring the file (interactively shows how the file is changing)

——————————————————————————–

LSOF:

NETWORK
-n no host name resolution
-P not converts port numbers to port names

lsof -i show all network connections
lsof -i| grep LISTEN shows what ports are waiting for connections
lsof -i | grep ESTABLISHED shows current active connections

lsof -i tcp list only TCP connections (works with udp as well)
lsof -i : shows all connections of a given port (lsof -i :22 or lsof -i :ssh)
lsof -i @ shows connections to a specific host (lsof -i @192.168.1.5)
lsof -i protocol:@ip:port this is the syntax for network findings (protocol: tcp or udp, @ip: any ip address, port: a port number)
lsof -a -u -i shows all network activity of a user (-a combines -u and -i)

USER, FILES, PROCESSES
lsof -u shows what is open for a user (lsof -u oracle)
lsof shows what is using a file (lsof /var/adm/syslog.log)
lsof shows what pids are using the filesystem (directory) (it can be good if we cannot umount)
lsof +D shows which file is open by which process in a directory (lsof +D /usr)
(+D will show recurcively the open files, otherwise only device name would be shown)
lsof -N list all NFS files
lsof -c shows files and network connections a command is using (lsof -c ssh)

lsof -p shows what a proccess ID has open (lsof -p 335545)

—————————–

HOW TO FIND WHAT FILES ARE OPENED BY A PID

1.
root@aix20: /root # lsof -p 319660
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ovcd 319660 root 32r VREG 10,5 12153 69705 /usr (/dev/hd2)

(it will show the filesystem and the indode number (69705))

2.
root@aix20: /root # find /usr -inum 69705
/usr/lpp/VV/msg/en_US/sec.cm.client.cat

——————————————————————————–

METACHARACTERS, VARIABLES:

GREP SHELL
single character . ?
multicharacter .* *
character range [x-z] [x-z]
begins a line ^ N/A
ends a line $ N/A
variable N/A $

HOME home directory
$PS1 prompt symbol
set displays the values of all shell variables

——————————————————————————–

RPM:

rpm -qa shows what rpm packages are installed
rpm -ql shows where the files are installed (rpm -qlp .. shows the absolut paths???)
rpm -q –filesbypkg cdrecord list all the files on installed rpm package
rpm -qf /usr/bin/lynx query a file to find the source rpm package
rpm -qi list information on an installed rpm package
rpm -qR list all dependencies on any rpm package

rpm -ivh httpd-2.2.8.aix5.1.rpm install the rpm package

rpm -ivh –force *.rpm
rpm -ivh –force –nodeps does not check dependency (same can be done with “rpm -Uvh…” for upgrade)
rpm -e removes the rpm package

rpm -Va shows which files are missing from the RPM database
rpm -Vv verifies a package
rpm –rebuilddb compress and rebuild the RPM database

/usr/sbin/updtvpkg enables the rpm command to recognize that the libraries have been installed

In some cases you might get an error about failed dependencies when you install RPMs on AIX (for example, error: failed dependencies: libX11.a(shr4.o) is needed by tk-8.3.3-1). Most likely the error occurs because the rpm command does not recognize the shared library. If the error occurs, check to see if the X11 libraries are installed in the directory /usr/lpp/X11/lib. If they are not installed, use the AIX product media to install them. After you have installed the libraries, run the above command (updtvpkg). The command enables the rpm command to recognize that the libraries have been installed.

——————————————————————————–

RSYNC:

Much like cp, rsync copies files from a source to a destination. Unlike cp, the source and destination of an rsync operation can be local or remote. rsync can resume a transfer after interruption; it transfers only those portions of a file that differ between source and destination; and rsync can perform entire or incremental backups.

By default, rsync uses Secure Shell (SSH) as its transport mechanism; you can reuse your machine aliases and public keys with rsync

rsync -av /tmp/bb_rs30 /tmp/bb it will copy the directory (/tmp/bb_rs30) and its contents under /tmp/bb
rsync -av /tmp/bb_rs30/ /tmp/bb it will copy the contents of the named directory but not the directory itself (check / at the end)
-v option enables verbose messages
-a option (stands for archive), is a shorthand for -rlptgoD:
recurse, copy symbolic links as symbolic links, preserve permissions, preserve file times,
preserve group, preserve owner, and preserve devices and special files, respectively

rsync -n -av /tmp/bb_rs30/ /tmp/bb -n: previews what will happen but does not move a single byte (it is good for testing)

rsync -av /tmp/bb_rs30/ aix2:/tmp/bb_rs20 it will copy the contents of the given dir to the other host
(assuming the same login name on the remote machine)

——————————————————————————–

SORT:

cat /etc/passwd | sort -t: -n +2
-t: gives the delimeter character (here :, deafult is the space)
-n numerical order
+2 sort by the 3rd column
-r reverse order

df -m | sort -n +3 | egrep ‘9.%|100%’ sorts by the 4th column (%) of the filesstems, which are 90-100% full
cat animals | sort +0.1 sort the file animals by the second character of the first word
ls -lR |sort -nk 5|tail -20 sorts the 20 largest file
lspv | sort -k1.6n list hdisk in numerical order (lspv|sort -tk +1 -n <--it is the same (delimiter is "k") lspv | sort -k1,1.5 -k1.6n list hdisks then vpaths in numeric order -------------------------------------------------------------------------------- TAR: tar -cvf /tmp/file.tar . saves where we are to the given path (-c: create, -v: verbose, -f: file) tar -cvf conf.tar conf creates conf.tar of the dir conf tar -xvf /tmp/file.tar extracts the tar file (-x: extract) tar -xvf -C /home/bb /tmp/file.tar it will extract the tar file to /home/bb tar -tvf /tmp/file.tar list (verify) the content of a tar file tar -cf - * | gzip -9 > vmi.tar.gz makes tar and zip wehere we are
tar cvf – openssh5.8p1 | gzip -c > openssh5.8p1.tgz creates tgz in one command

tar: 0511-197 DirectorServer: Cannot write data extracted with the tar command:
A file cannot be larger than the value set by ulimit.

I changed these ulimit settings after that it was OK (dont’t forget to logout and login again)
root@bb_lpar: /bb # chuser fsize=-1 fsize_hard=-1 root
root@bb_lpar: /bb # chuser data=-1 data_hard=-1 root

——————————————————————————–

TRUSS:

truss it will show what system calls a command makes
truss -c -p it will trace a process (-c: counts the system calls rather than displaying them, -p: pid)
truss -d -p -o
truss -t open lsps -a shows whatis needed for the given command (here lsps -a)

——————————————————————————–

XARGS:

lspv|awk ‘{print$1}’|xargs it will list the elements in a line separated with space
cat list | xargs -t rm will rm all the files which are in the file list
ls | xargs -t -I {} mv {} {}.old it will rename to .old all the file in the current dir
-t it echoes the constructed command (trace mode) (it is optional)
-I {} insert each line of the ls to that place where the {} symbol appear

lsdev -Cc disk | xargs -n1 rmdev -dl removes all the listed disks
-n1 1 element will be passed each time to xargs (if n2 then the command will be created with 2 elements)

——————————————————————————–

ZIPPING:

gzip-V shows gzip version
gzip file1 zip
gzip -d file1.gz unzip

gzip -9 filename will zip (and remove the file automatically)
gunzip filename unzipping it

gzip -c file > file.gz it creates a zip file but leave the original file as well
> filename after that original file can be emptied

compress file1 the original file will be deleted and a new compressed file will be created with a .Z at the end
zcat file1.Z displays the compressed files (without uncompression)
uncomress file1.Z uncompressing a file (the compressed one will be deleted)

if you receive this:
gunzip SysDir6_2.tar.gz
gunzip: SysDir6_2.tar: File too large

this is because gzip 1.2.4 (or lower gzip versions) need a patch to accept large files, workaround for this problem:
gzip -d -c SysDir6_2.tar.gz| tar xvf –

——————————————————————————–

OTHER:

file shows the type of a file

diff file1 file2 compares only text files
cmp file1 file2 compares all types of files
dircmp dir1 dir2 compares directories

time cp file1 /home show the time to accomplish the command (godd for performance analysis)

ps $$ shows which shell is in use
echo $SHELL shows the current shell
printenv view environmental variables

cat -vet file shows tabs, enters… as viewable characters
-v displays non-printing characters as visible characters
-t displays tab as ^I
-e displays enter as $

!!! sh -xv for troubleshooting, if a command fails, you can see where exactly it failed in the command script!!!
(sh -xv exportvg rootvg)

dd if=/dev/zero of=/home/user/bb/4GB_file bs=1m count=4000 it creates a 4GB file
lmktemp it creates a file with given size

alias dir=’ls’ creates an alias
unalias dir removes an alias
set – unset

df -g | awk ‘{sum = sum + $3} END {print sum}’ it sums up the fs in gigabyte (by the 3rd column)
for i in `ls -l | grep old | awk ‘{print $9}’` ; do du -sk $i; done | awk ‘{sum = sum + $1} END {print sum}’

CPU – PROCESSES:

Physical – Virtual – Logical CPU:

Physical Processors are cores in the machine. Virtual Processors are assigned to an LPAR manually when LPAR is created. Logical Processors are created automatically by AIX, depending on the SMT setting.

1

Simultaneous Multi-Threading (SMT)
SMT is that feature of a Power Processor, when multiple hardware threads can run on one physical processor at the same time (a processor appears as 2 or 4 logical CPU). Within a CPU (core/cpu/processor are the same thing) there are multiple execution units. For example: floating point arithmetic unit, load and store execution units… A single thread would use only 1 or 2 of those units at any point in time. So most of the executional units within a core will not be utilized. With the ability of multi-threading 2 (or 4) threads could be running in a core at same time. One of them will use the floating processor while the other doing load and store …(If there are collisions, one of them would be delayed but it happens no too often.)

How threads will be dispatched to multiple cores:
First thread will be dispatched to the primary hw thread of a physical cpu. If we have another CPU then next thread will be dispatched there (to avoid collision)

Capture

IMPORTANT:

– Prior AIX6 TL4: if only a single hw thread was busy, processor reported as 100% utilized (this is an error because all the secondary threads were not utlized)

– AIX6 TL4 and later: potential capacity of unused hw threads are from TL4 reported as idle time for the processor (it measures the capacity of the unused hw threads.)

————————

SMT behaviour and intelligent SMT threads:

AIX default behaviour is to use all the VPs for maximun performance. If workload grows it will use up all VPs (CPU cores) quickly, but AIX first uses SMT thread 1 on all CPU cores before allocating work to the 2nd, 3rd and 4th SMT threads.

SMT threads can be seen as Logical CPUs on AIX. If SMT=4 then 1 VP shows up as 4 Logical CPU. From Power7 there is a thing called “intelligent SMT threads”. If there are not enough processes to run on all SMT threads (official mode is SMT=4) it will be dynamically switched to 2 or 1.

mpstat or topas -L is showing it:

At the column “lpa” the sign “-” will show turned off SMT threads

# mpstat 2

cpu min maj mpc int cs ics rq mig lpa sysc us sy wa id pc %ec lcs
0 0 0 0 265 35 24 2 0 100 64 100 0 0 0 0.63 31.7 99
1 0 0 0 12 12 0 0 0 100 9 0 0 0 100 0.12 6.1 22
2 0 0 0 9 0 0 0 0 – 0 0 0 0 100 0.12 6.1 20 <--this SMT thread is turned off 3 0 0 0 9 0 0 0 0 - 0 0 0 0 100 0.12 6.1 19 <--this SMT thread is turned off 4 0 0 0 100 12 8 1 0 100 0 100 0 0 0 0.64 31.8 99 5 0 0 0 19 59 0 0 0 100 9 0 0 0 100 0.12 6.1 69 6 0 0 0 9 0 0 0 0 - 0 0 0 0 100 0.12 6.1 9 <--this SMT thread is turned off 7 0 0 0 9 0 0 0 0 - 0 0 0 0 100 0.12 6.1 9 <--this SMT thread is turned off ALL 0 0 0 432 118 32 3 0 0 82 63 0 0 37 2.00 999.8 346 -------------------------------------------------------------------------------- ------------------------ Context Switch: It is inherent in any multiprocessing operating system. Different appl. threads are sharing a CPU. Every time 1 thread is leaving a CPU and a new thread is dispatched to the CPU, a context switch occurs. The environment of the leaving one has to be saved and new environment ha to be reestablished for the new process. High context switch rates can cause many work (overhead) for the CPU, which can be a problem. ------------------------ PROCESS: You use commands to tell the operating system what task you want it to perform. When commands are entered, they are recognized by a command interpreter (also known as a shell), and the task is processed. A program or command that is actually running on the computer is referred to as a process. The commom types of processes: Foreground processes Processes that require a user to start them or to interact with. Programs and commands run as foreground processes by default. Background processes Processes that are run independently of a user. To run a process in the background, type the name of the command with the appropriate parameters and flags, followed by an ampersand (&). When a process is running in the background, you can perform additional tasks by entering other commands at the command prompt. Most processes direct their output to standard output (stdout), even when they run in the background. Because the output from a background process can interfere with your other work on the system, it is usually good practice to redirect the output of a background process to a file. Daemon processes Daemons are processes that run unattended. They are constantly in the background and are available at all times. Daemons are started usually when the system starts, and they run until the system stops. A daemon process typically performs system services. For example qdaemon (provides access to system resources such as printers) and sendmail are daemons. Zombie processes A zombie process is a dead process that is no longer executing but is still recognized in the process table (in other words, it has a PID number). Zombie processe have been killed or have exited and continue to exist in the process table until the parent process dies or the system is shut down and restarted. Zombie processes display as when listed by the ps command. The only way to remove zombies is to reboot the system.

Thread
Each process is made up of one or more kernel threads. A thread is a single sequential flow of control. Rather than duplicating the environment of a parent process, as done via fork, all threads within a process use the same address space and can communicate with each other through variables.

——————————

Process priority

A priority is a number assigned to a thread. The kernel maintains a priority value (0-255). A smaller priority value indicates a more important thread. Real time thread priorities are lower than 40.

Nice value
A nice value is a priority adjustment factor added to the base user priority of 40 (for non-fixed priority threads). The nice value is used by the system to calculate the current priority of a running process. The first process in the system (init) has a nice value of 20, and therefore an effective priority of 60. (PRI heading in the below output) A foreground process has a nice value of 20 (24 for a background process).

ps -el shows process priorities
ps -ekl shows process priorities including kernel processes
ps -kmo THREAD shows processes with their threads priorities

root@aix31: / # ps -el <--shows the nice values under the NI heading (-- means it is running with fixed prio. F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 200003 A 0 1 0 0 60 20 7037000 784 - 0:39 init 200103 A 0 311326 352456 0 24 -- 81d8400 4676 - 1:15 xmtopas The nice value can be set at process creation time by using the nice command. If the process already created the renice command is used. (ksh will add automatically 4 to the default nice value (20) if a process is started in the background (&)) The nice value can be ranged from 0 to 39, with 39 being the lowest priority. nice -10 add 10 to current nice value (lower priority)
nice –10 subtract 10 from current nice value (higher priority)

The renice value can be -20 to 20. (1-20: lowers the priority, 0:sets to the base scheduling priority, -20 to -1:highers the priority)
renice 10 -p add 10 to the default nice value (20) (lower priority)
renice -n 10 -p add 10 to current nice value (lower priority)
renice -10 -p subtract 10 from the default nice value (20) (higher priority)
renice -n -10 -p subtract 10 from current nice value (higher priority)
(-n: incerment is added to the current nice value, not default)

—————————

CPU infos:

lscfg | grep proc shows how many (virtual) processors we have (lsdev -Cc processor, shows also how many virt. proc we have)
bindprocessor -q shows how many logical (SMT) processors we have
lsattr -El procX shows the processor settings
pmcycles -m shows the processors speed (if smt is enabled it will show for all the logical processors)
smtctl it will show how many processor we have (if smt is turned on or not)

—————————

Process handling:

Ctrl-C or Ctrl-Backspace cancels a foreground process

ps lists processes (by default lists only processes started from the current terminal)
-e every process runnning on the system
-f full listing (username, PPID…)
-L lists all processes which PPID is -u lists all processes running under
-T lists the tree of a given process (shows the children of a given process)

ps -elmo THREAD lists processes and its threads (shows pids and the threads (tid) which belong to a given process)

proctree displays the process tree of the specified process

kill notification to the process to terminate (it is using the default, 15, signal)
kill -9 kills the process without notification
kill -1 restarts the process (rereads the config files as well) (HUP – hangup)
(when a background process is running and you log off a hangup signal is sent)
kill -2 interrupt signal (same as ctrl+c)
kill -l lists all the signals supported by kill (cat /usr/include/sys/signal.h will show as well, with details)

ls -R / > ls.out & starts ls in the background (standard output is ls.out)
nohup ls -R / > ls.out & nohup allows a background process to continue after logging off the system
(if output isn’t redirected, it will create nohup.out)
echo “” | at now this also starts in the background (and you can log off)
jobs lists which processes are running in the background

nohup alt_disk_copy -d hdisk1 -B & can’t be hanged up and in backgound (kill command can stop it)

Restarting a stopped foreground process (jobs command):
1. Ctrl-Z stops a foreground process, its PID is still in the process table (it goes to background)
2. jobs this will list stopped processes
[1] + Stopped (SIGTSTP) ./myscript <--you will see a line like this (here #1 is the job id) 3. fg %1 put given job into foregeound (bg %1 puts into background) Restarting a stopped foreground process (ps -ef ):
1.Ctrl-Z stops a foreground process, its PID is still in the process table (it goes to background)
2.ps -ef | grep find the process ID (PID)
3.fg restarts that stopped proces (it will go to foreground)

Removing a background process:
1.find / -type f > output & run the find command in the background
2.ps lists the PID numbers
3.kill cancel the process

——————————

The operating system allows you to manipulate the input and output (I/O) of data to and from your system. For example you can specify to read input entered on the keyboard (standard input) or to read input from a file. Or you can specify to write output data to the screen (standard output) or to write it to a file.

When a command begins running, it usually expects that the following files are already open: standard input, standard output and standard error. A number, called a file descriptor, is associated with each of these files:

0 represents standard input (stdin)
1 represents standard output (stdout)
2 represents standard error (stderr)

The redirection symbols and their meanings:
< redirects input (stdin) (< filename is added to the end of the command) > redirects output (stdout) (> filename is added to the end of the command)
>> appends output
<< inline input (see pg. 574) 2> redirects output (stderr)
1>&2 redirects stdout to stderr
2>&1 redirects stderr to stdout

mail denise < letter1 sends the file letter1 to user denise with the mail command echo $PATH > path1 saves the value of the PATH variable on the file path1
cat file2 >> file1 append file2 to file1 (the cat commands can concatenate not only display files)
ls -l file1 2> list1 save the stderr to file list1 (if file1 does not exist)
ls *.dat *.txt > files.out 2> files.err (files.out: stdout, file.err: stderr)
command > output 2>&1 saves all the output (stdout and stderr) in one single file

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>