Saturday, October 30, 2021

How to check and change VIO shared ethernet adapter status,ha_mode using script

Use following scripts for shared ethernet adapter failover, status and priority check

Let's start

1.
Check ha_mode on multiple shared ethernet adapter in VIO .

for i in `lsdev -Cc adapter | grep -i shared |awk '{print $1}'`
do
echo "-------shared SEA $i  ha mode------ "
lsattr -El $i |grep -i ha_mode
sleep 2
done
≠==≠=========
Output will be:
All shared ethernet adapter in VIO and their ha_mode


2.Script to display shared ethernet adapter "state, priority and active status.

for i in `lsdev -Cc adapter | grep -i shared |awk '{print $1}'`
do
echo "-------shared SEA $i  state priority and active status ------ "
entstat -d $i | grep -E  "^ *state|priority.*Active"
echo "---------------------"
sleep 2
done

3.Script to change shared ethernet adapter "ha_mode" . This script useful for failover and failback.

If Unix admin execute following script on vio server on which shared ethernet adapter is primary it will become backup.

for i in `lsdev -Cc adapter | grep -i shared |awk '{print $1}'`
do
echo "-------shared SEA $i  failover to partner VIO------ "
chdev -l $i -a ha_mode=standby
echo "---------------------"
sleep 2
done

4.If Unix admin execute following script on primary VIO where shared ethernet adapter already fail overed to its partner VIO because of some incident and admin wanted to failback from parter VIO or secondary VIO to primary VIO .


for i in `lsdev -Cc adapter | grep -i shared |awk '{print $1}'`
do
echo "-------shared SEA $i  failback to primary VIO------ "
chdev -l $i -a ha_mode=auto
echo "---------------------"
sleep 2
done


Thanks!!!!


How to gzip thousands of files using for loop

UNIX admin may get task like housekeep Unix filesystem.

 In such situations he may housekeep existing files in the file system or increase file system. Few day back I got such ticket but there was no scope for increasing file system size, so decided to find which files occupying space on that file system.

Finally found more than  2000 files, now question is how to gzip those??

Solution:

Step 1 created directory named like following,
#mkdir /tmp/housekeep

Then created file "listfiles" using touch command and redirected all files inside that file. Cross check done whether it contain correct files only , which we are going to gzip.
Step 2
#touch listfiles
#vi listfiles // add all files which need to be gzip
Step 3

Use following for loop
for i in `cat listfiles`
do
gzip $i
done

UNIX admin can check whether gzip happening or not by executing a following command  in target directory

#ls -lrt *.gz |wc -l

Or by simply take another session of server and execute while loop with above command

While true
do
ls -lrt *.gz |wc -l
sleep 1
done

**Before doing gzip make sure that it will not impact any production application or database.

Usefull command to find files modified in last hours
Print files which are modified in last 24 hrs
#find /var -mtime -1 -print

Thanks !!