====== AIX: Tips and Tricks ======
==== Sum multiple lines ====
root@prod /root> ps vx | sort -rn +4 | awk '{print $5}'
68087
2186
2186
898
704
700
578
560
550
508
root@prod /root> ps vx | sort -rn +4 | awk '{print $5}' | paste -s -d+ -
68087+2186+2186+898+704+700+578+560+550+508+
root@prod /root> ps vx | sort -rn +4 | awk '{print $5}' | paste -s -d+ - | bc
76957
==== bash, absolute value ====
If a if > or < 0, this will give a value >0
$ a=-3
$ echo ${a#-}
3
==== Encode password : Base64 Encoding ====
**For encode in aes-256**
Decode password in tsmadmin.pwd file with a passphrase:
# openssl enc -d -aes-256-cbc -in /etc/security/tsmadmin.pwd -pass pass:YHlj55Xva26o48J
Encode a new password in tsmadmin.pwd file
First create a file secrets.txt and include new password in it.
Encode password in tsmadmin.pwd file :
# openssl aes-256-cbc -a -in secrets.txt -out /etc/security/tsmadmin.pwd
It will request a passphrase for the encryption, use YHlj55Xva26o48J as passphrase
Also verify the permissions of the file.
**For encode in base64**
To encode a file text.plain you can use
$ openssl enc -base64 -in text.plain -out text.base64
To decode a file the the decrypt option (-d) has to be used
$ openssl enc -d -base64 -in text.base64 -out text.plain
Generate a 16 character password.
$ openssl rand -base64 16
b4all5h6+sLvYh1TPl13yw==
==== get file permissions in octal ====
# stat -c"%a %G %U" dokuwiki-stable_2018-04-22b.tgz
700 apache apache
==== Random counter ====
In HEXAdecimal
# openssl rand -hex 12
ca36096f8eb60866593c022f
Print a random number in decimal between 0 and 51
# let rand=$RANDOM%52
# echo $rand
==== Suppress non ascii character ====
> cat .sh_history
�f #�#67#�#
fc -t #�#6604#�#
> cat .sh_history | perl -pe 's/[^[:ascii:]]//g'
df ##1559655978##
fc -t ##1559656904##
==== Convert epoch to human readable date ====
Required **coreutils** RPM package
# alias TS='_TS(){ /opt/freeware/bin/date --date="@$1" +%Y/%m/%d-%T ; }; _TS'
# TS 1502208414
2017/08/08-18:06:54
What is the last login date for all users that try a connection:
# alias TS='_TS(){ /opt/freeware/bin/date --date="@$1" +%Y/%m/%d-%T ; }; _TS'; lsuser -a time_last_login ALL | grep last | sed 's/time_last_login=//' | while read i j; do echo $i $(TS $j); done
root 2018/10/25-13:25:03
toto 2018/10/25-16:05:32
Usung perl:
[root@aix01] /root/scripts> perl -le 'print scalar localtime $ARGV[0]' 1268727836
Tue Mar 16 09:23:56 2010
Convert seconds in hours,minutes,seconds
# /opt/freeware/bin/date -u -d @6789 +"%T"
01:53:09
https://linuxconfig.org/how-to-count-days-since-a-specific-date-until-today-using-bash-shell
==== Compare files on different servers ====
# ssh user@remote "cat /path/to/remote/file" | diff - /path/to/local/file
==== Verification of environment settings for a running process under AIX ====
**ps eww **
(ps e displays the environment as well as the parameters to the command, up to a limit of 80 characters, ps eww wraps the display from the e flag and displays the ENV list until the flag reaches the LINE_MAX value)
//Ex:// Check NSORDER if set during process startup
ps -ef | grep ora_smon |grep -v grep | awk '{print $2}' | xargs -n1 ps eww | grep NSORDER
==== log ftpd sessions ====
Using ftpd daemon with option -l Sends logging information about ftpd daemon operations to the syslogd daemon. If you specify the -l flag, you must edit the /etc/syslog.conf file and add the following entry:
daemon.info /var/log/ftp.log
Create the log file, and refresh syslogd:
# touch /var/log/ftp.log
# refresh -s syslogd
I think you need to edit inetd.conf to include the -l option to have it log by default:
ftp stream tcp6 nowait root /usr/sbin/ftpd ftpd -l
Refresh inetd:
# refresh -s inetd
# lssrc -ls ined
Also available : ftpd -d to debug the use daemon.debug
==== Size of the terminal ====
Print the current number of lines and columns of your tty
aixsrv # resize
COLUMNS=132;
LINES=40;
export COLUMNS LINES;
==== Start a program in background ====
# echo “/some_dir/myscript.sh” | at now
==== Find files or directories not belonging to a user or group ====
# find / -nouser
# find / -nogroup
==== Find files or directories belonging to a user or group and change it ====
To change a userID / groupID, first top all processes from user
initial userID and groupID is 100 and 150, so first change into /etc/passd and /etc/group, then do it in 2 steps: user and then group
# find / -user 100 -exec chown myuser {} +
# find / -user 150 -exec chgrp mygrp {} +
You can aslo do it like
find / -user 100 -exec chown myuser {} \;
==== Increase perf on NFS ====
NFS mount slow when accessing with sequential access (Ex TSM)
First, you set some AIX "nfso" tunables to their max values as follows:
# nfso -p -o nfs_max_write_size=524288
# nfso -p -o nfs_max_read_size=524288
(Use "nfso -L nfs_max_read_size" to see if the 'max' value of your system can go that high - otherwise you have some patching to look forward to. :-) )
...which then allows you to mount the NFS shares with the respectively higher values as well - ie use the mount options:
rsize=524288,wsize=524288
==== Change AIX device default attributes with "chdef" command ====
In addition, if you change an attributes default value with chdef, all of the current devices will take on this default value unless you had specifically set them to have a value (if they used the default before, and you change the default with chdef, then all current devices inherit the new default). The only "gotcha" here is that if it is an attribute that requires a reboot to take effect you need to reboot for the new default attribute to become active for all the current devices (even though "lsattr" will lie and appear to show that it is active even though you need a reboot, similar to what "chdev -P" causes. You can use "lsattr -P" to see this if running very new AIX versions). If you had specifically set a device to have a value for one of their attributes, it will not be changed when you use "chdev" to change the default.
For info ODM DB is : PdAt
**Example**
Change default vscsi_path_to to 30:
# chdef -a vscsi_path_to=30 -c adapter -s vdevice -t IBM,v-scsi
Change default vscsi_err_recov to fast_fail:
# chdef -a vscsi_err_recov=fast_fail -c adapter -s vdevice -t IBM,v-scsi
Change default for Hitachi disk reserve_policy to no_reserve:
# chdef -a reserve_policy=no_reserve -c disk -s fcp -t Hitachi
==== Sort files/folder by size ====
/opt # du -sm ./* | sort -n
0.00 ./cam
0.00 ./lost+found
...
0.78 ./IBM
1.57 ./Tivoli
11.25 ./IBMinvscout
17.12 ./csm
18.85 ./ibm
24.07 ./tivoli
48.29 ./LicenseUseManagement
377.80 ./freeware
==== Find based on size ====
Find files bigger than 1M (2048 in 512k blocs)
# find /tmp -xdev -size +2048 -ls
==== Get memory usage of biggest consumers with svmon ====
# svmon -P -O summary=basic,unit=GB
Unit: GB
——————————————————————————-
Pid Command Inuse Pin Pgsp Virtual
5963998 db2sysc 65.6 0.04 6.46 65.7
12190188 db2vend 64.3 0.03 6.44 64.4
==== AIX print special characters in a file ====
# od -c file_name
0000000 \t i d = 1 4 3 5 \n \t p g r p = s
0000020 y s a d m i n \n \t g r o u p s =
0000040 s t a f f \n
==== AIX sed or tr to remove tab (011) or other special characters ====
(Ex: ctrl+M 015) in a file, using octal character code:
# tr -d "\011" file_name > file_name1
or
# sed 's/'"$(echo '\011')"'//g' file_name
or
# /opt/freeware/bin/sed 's/^[ \t]*//' file_name
http://www.unix-manuals.com/refs/misc/ascii-table.html
==== Encrypt a password using different algorithm ====
# perl -e 'print crypt("password", "aes256"),"\n"'
aeC10Dk/ExaG.
==== Password are limited to 8 character ====
This is maximum length with the standard AIX algorithm. You have to select an other algorithm to have up to 255 character:
# chsec -f /etc/security/login.cfg -s usw -a pwd_algorithm=smd5
==== Hostname full qualified (FQN) can't be changed even if reboot ====
In such HACMP version, it hard code the full qualified hostname (long name), and the IP address into /etc/rc.net
Solution: suppress these bad line from file
==== old IP address is reapply during reboot ====
In such HACMP version, it hard code the full qualified hostname (long name), and the IP adress into /etc/rc.net
Solution: suppress these bad line from file
==== Create a big file called test which size is 100m (very fast) ====
# /usr/sbin/lmktemp test 100m
==== Rename a device (AIX6.1 TL6 minimum) ====
# rendev -l hdisk1 -n hdisk99
==== Start sendmail demon: ====
# startsrc -s sendmail -a "-bd -q30m"
==== Force to free the mailqueue ====
# sendmail -v -q -O QueueLA=150 -O RefuseLA=199
==== Extend logical volume ====
** error maximum allocation **
By default AIX logical volumes are limited to 512 PP (physical partitions), this is a soft value which was used to prevent an excessive increase of a filesystem, before when they can't be shrink online on previous AIX version.
# chfs -a size=+40G /wpars/r6db10/oradata/r6db10/data
0516-787 extendlv: Maximum allocation for logical volume fslv10
is 7600.
# chlv -x 10000 fslv10
==== Migrate a single PP to another disk ====
migratelp LVname/LPartnumber[ /Copynumber ] DestPV[/PPartNumber]
Ex:
[root@labotest]/root# lspv
hdisk0 00522e1d4d4bc4ce rootvg active
hdisk1 00522e1d2219e9fb rootvg active
hdisk7 00522e1dbe9aef35 nimvg active
hdisk8 00522e1dbe9af0ea nimvg active
[root@labotest]/root# lspv -M hdisk0 | head -1
hdisk0:1 hd5:1:2
[root@labotest]/root# lspv -M hdisk0 | head -10
hdisk0:1 hd5:1:2
hdisk0:2-75
hdisk0:76 tmplv:210
hdisk0:77 tmplv:211
hdisk0:78 tmplv:212
hdisk0:79 tmplv:213
hdisk0:80 tmplv:214
hdisk0:81 tmplv:215
hdisk0:82 tmplv:216
hdisk0:83 tmplv:217
[root@labotest]/root# migratelp tmplv/210 hdisk1
==== Convert UNIX library file .a into .so ====
Sometime, mostly for freeware package, you'll need a library file called .so instead of common AIX .a, then you can use the ar command which add a new package .so based on the conversion of AIX .a library file
[root@test]/opt/freeware/lib# ls -l libXpm*
-rwxr-xr-x 1 root system 388738 Nov 08 2010 libXpm.a
[root@test]/opt/freeware/lib# ar -x libXpm.a
[root@test]/opt/freeware/lib# ls -l libXpm*
-rwxr-xr-x 1 root system 388738 Nov 08 2010 libXpm.a
-rwxr-xr-x 1 root system 120524 Jun 17 14:55 libXpm.so.4
[root@test]/opt/freeware/lib# ln -s libXpm.so.4 libXpm.so
[root@test]/opt/freeware/lib# ls -l libXpm*
-rwxr-xr-x 1 root system 388738 Nov 08 2010 libXpm.a
lrwxrwxrwx 1 root system 11 Jun 17 15:02 libXpm.so -> libXpm.so.4
-rwxr-xr-x 1 root system 120524 Jun 17 14:55 libXpm.so.4
==== Set PVID on newly configured hdisk ====
# chdev -l hdisk1 -a pv=yes
==== Print disk size even if it doesn't belong to a VG ====
# getconf DISK_SIZE /dev/hdisk1
# bootinfo -s hdisk1
==== List all LV on a PV: ====
[root@powerha1] # lqueryvg -p hdisk0 -L
00f813df00004c000000013d59aad4f1.1 hd5 1
00f813df00004c000000013d59aad4f1.2 hd6 1
00f813df00004c000000013d59aad4f1.3 hd8 1
00f813df00004c000000013d59aad4f1.4 hd4 1
00f813df00004c000000013d59aad4f1.5 hd2 1
00f813df00004c000000013d59aad4f1.6 hd9var 1
00f813df00004c000000013d59aad4f1.7 hd3 1
00f813df00004c000000013d59aad4f1.8 hd1 1
00f813df00004c000000013d59aad4f1.9 hd10opt 1
00f813df00004c000000013d59aad4f1.10 hd11admin 1
==== SSH connection slow ====
Check into the configuration file /etc/ssh/sshd_config, comment the Listen on IPV6, and restart sshd demon:
vi /etc/ssh/sshd_config
ListenAddress 0.0.0.0
#ListenAddress ::
==== Debug for an AIX service ====
To enable the debug on a service:
startsrc -s qdaemon -a " -D/tmp/qdaemon.log"
==== AIX devices attributes ====
To list all devices
# # lsdev -C | more
...
en0 Available Standard Ethernet Network Interface
ent0 Available Virtual I/O Ethernet Adapter (l-lan)
et0 Defined IEEE 802.3 Ethernet Network Interface
fcs0 Available C5-T0 Virtual Fibre Channel Client Adapter
fcs1 Available C6-T0 Virtual Fibre Channel Client Adapter
hdisk4 Available C7-T1-01 MPIO IBM 2076 FC Disk
hdisk5 Available C7-T1-01 MPIO IBM 2076 FC Disk
sys0 Available System Object
To query current setting of a device:
# lsattr -D -l sys0 -a maxuproc
To set to a different value:
# chdev -l sys0 -a maxuproc='4096'
==== Update AIX rpm virtual package ====
If you want to run the command manually:
# /usr/sbin/updtvpkg
If you get an error similar to "cannot read header at 20760 for lookup" when running updtvpkg, run a rpm rebuilddb:
# rpm --rebuilddb
==== Hardware date ====
date -u
==== Change console settings from vty0 to vty1 ====
[root@nimsrv]/root# lscons -a
current = /dev/vty0
console_logname = /var/adm/ras/conslog
console_logsize = 32768
console_logverb = 1
console_tagverb = 0
[root@nimsrv]/root# chcons -a login=enable /dev/vty1
==== Copy datas from one filesystem to another ====
cpio: copy all data but not sure for files bigger than 2GB\\
rsync: copy everything except special files (like bloc or character files)
# find /origfs -print | cpio -pvdmu /newfs
# rsync -grouptlvS /src_dir/ /dst_dir/
==== Binary in 32 or 64 bits ====
# dump -ov /usr/bin/bzip2
/usr/bin/bzip2:
***Object Module Header***
# Sections Symbol Ptr # Symbols Opt Hdr Len Flags
4 0x00000000 0 72 0x100f
Flags=( RELFLG EXEC LNNO LSYMS DYNLOAD DEP_SYSTEM )
Timestamp = "Sep 17 16:56:31 2009"
Magic = 0x1df (32-bit XCOFF)
==== Library in 32 or 64 bits ====
Check if you have an error or not
nm -X32 libmod_sm20.so
nm -X64 libmod_sm20.so
==== Disable SSH prompt ====
Using commad line:
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR
Using a user config file: for a specific user create a file into home directory's .ssh/config, or for all users into /etc/ssh/ssh_config (LogLevel can also be QUIET : no error)
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
LogLevel ERROR
==== Edit a file on a remote host ====
Use ssh command with -t option
==== VI: edit large files without out of memory problem ====
In case of memory problems:
ex: 0602-101 Out of memory saving lines for undo.
By exporting the following variable, we can edit large files without having the out of memory problem:
export EXINIT="set ll=20000000"
==== Find all commands containing a word ====
Add the following alias in your .profile
alias lscmd='for dir in `echo $PATH | tr ":" " "`; do for file in `ls -1 "$dir"`; do [ -x "$dir/$file" ] && echo $file; done; done | sort | uniq'
You can also run something like "lscmd | grep vary" to see commands that contain the word "vary" in them:
# lscmd | grep vary
ipl_varyon
lvaryoffvg
lvaryonvg
varyoffvg
varyonvg