|
|
dave spink toolset |
|
|
FTP MOVERFTP doesn't issue a file lock, and we had external customers sending files 24 * 7. We needed a method to first check a file wasn't being FTP'd by a customer before moving the file for internal processing.
#!/bin/ksh
#
# Purpose: Tests if files are being FTP'd by a customer before moving them into a collection area for ehub.
# Created by: David Spink
# Create Date: Feb 20, 2003
#
cd /export/ftp
for FILER in `find ./pubftp/*/inbound -type f`
do
fuser $FILER 2>&1 | awk -F: '{print $2}' | grep "[0-9][0-9]o$"
if [ $? -eq 1 ]
then
myfile=`basename $FILER`
mydir=`dirname $FILER | sed "s/pubftp/ehubgate/"`
mkdir -p $mydir
mv -f $FILER $mydir
chown ehubgate:ehubftp $mydir
chown ehubgate:ehubftp $mydir/$myfile
fi
done
DMX GORUNTo quickly and repeatedly without error provision storage on a DMX. The script automates creation of metas, hyper selection, maps to FA, masks VCM, and displays results. gorun.sh
#!/bin/ksh
echo mysid $mysid myhost $myhost
#metas
echo "metas y/n: \c"
read ans
if [ $ans = "y" -o $ans = "Y" ]; then
echo "elected to make metas"
gometa.sh
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
fi
#hypers
echo "hypers y/n: \c"
read ans
if [ $ans = "y" -o $ans = "Y" ]; then
echo "elected to get hypers"
gohype.sh
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
fi
#scsi3
echo "Set SCSI-3 y/n: \c"
read ans
if [ $ans = "y" -o $ans = "Y" ]; then
echo "elected to set SCSI-3"
for i in `cat hypers.txt`
do
echo "set dev $i attribute=SCSI3_persist_reserv;" >> on_scsi3.txt
done
echo "elected to set SCSI-3"
sudo symconfigure -sid $mysid -f on_scsi3.txt preview -noprompt
sudo symconfigure -sid $mysid -f on_scsi3.txt prepare -noprompt
sudo symconfigure -sid $mysid -f on_scsi3.txt commit -noprompt
fi
#map
echo "map"
map_file.sh > fa_map.txt
cat fa_map.txt
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
sudo symconfigure -sid $mysid -f fa_map.txt preview -noprompt
sudo symconfigure -sid $mysid -f fa_map.txt prepare -noprompt
sudo symconfigure -sid $mysid -f fa_map.txt commit -noprompt
for i in `cat hypers.txt`
do
echo $i
sudo symdev -sid $mysid show $i | egrep '(FA |WD| NR)'
done
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
#mask
sudo symmaskdb -sid $mysid list database > vcm_pre.txt
echo "check hyper not already in vcmdb"
for i in `cat hypers.txt`
do
echo $i
grep $i vcm_pre.txt
done
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
. mydevs.sh
export mydevs
mask_file.sh > mask_file.txt
cat mask_file.txt
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
chmod u+x mask_file.txt
echo "masking"
./mask_file.txt
chmod u-x mask_file.txt
mask_check.sh
echo "Label VCM y/n: \c"
read ans
if [ $ans = "y" -o $ans = "Y" ]; then
echo "elected to label"
mask_label.sh > mask_label.txt
cat mask_label.txt
chmod u+x mask_label.txt
echo "label"
./mask_label.txt
chmod u-x mask_label.txt
fi
sudo symmaskdb -sid $mysid list capacity -host $myhost > capt_${myhost}.txt
for i in `cat hypers.txt`
do
echo $i
grep $i capt_${myhost}.txt
done
sudo symmask -sid $mysid refresh
mask_display.sh
DMX METAThe "gometa.sh" script builds metas. It requires a "cusreq.txt" file that contains type, size, and qty. This script extracts the meta definitions and selects unused devices from the array. It first displays the devices so that you can check attributes. It then builds the number of metas based on member needs defined in "cusmet.txt". Ensure your cusreq.txt file exists. # cat cusreq.txt hyper 3375 10 hyper 30713 8 hyper 61425 4 meta 30713 12 Ensure your cusmet.txt file exists, for example, two metas will be created one 8 way and other 4 way. # cat cusmet.txt 30713 8 30713 4 gometa.sh
#!/bin/ksh
# mysid=XXXX
# Get unused hypers
rm hypers-tmp.txt > /dev/null 2>&1
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
cc=`echo $LINE | awk '{print $3}'`
if [[ $aa == "meta" ]]; then
sudo symdev -sid $mysid list -noport | grep $bb | grep -v "(M)" | grep -v "WD" | awk '{print $1}' | head -n $cc >> hypers-tmp.txt
fi
done < cusreq.txt
for i in `cat hypers-tmp.txt`
do
echo $i
sudo symdev -sid $mysid show $i | egrep '(Mega|FA |WD|Configuration|RDF|SCSI-3 Persistent| N/A)'
echo ""
done
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
# Build meta
meta_build.sh > meta_create.txt
cat meta_create.txt
echo "Proceed y/n: \c"
read ans
if [ $ans = "n" -o $ans = "N" ]; then
echo "elected not to proceed"
exit
fi
sudo symconfigure -sid $mysid -f meta_create.txt preview -noprompt
sudo symconfigure -sid $mysid -f meta_create.txt prepare -noprompt
sudo symconfigure -sid $mysid -f meta_create.txt commit -noprompt
grep "from dev" meta_create.txt | awk '{print $5}' | cut -d, -f1 > hypers.txt
for i in `cat hypers.txt`
do
echo $i
sudo symdev -sid $mysid show $i | egrep '(Meta Configuration|MegaBytes|Meta Device Members|RDF|SCSI-3 Persistent)'
done
The "meta_build.sh" script is called from "gometa.sh". Its job is to form the meta file in preparation for symconfigure. meta_build.sh
#!/bin/ksh
typeset -i pos
typeset -i num
typeset -i metacnt
typeset -i metamem
# Load devices into an array
pos=0
for DISKS in `cat hypers-tmp.txt`
do
(( pos = pos + 1 ))
my_dev[$pos]=$DISKS
done
num=pos
pos=1
while IFS= read LINE
do
metamem=`echo $LINE | awk '{print $2}'`
metacnt=1
aa=${my_dev[$pos]}
echo "form meta from dev ${aa}, config=striped;"
while (( metacnt < metamem ))
do
(( pos = pos + 1 ))
echo "add dev ${my_dev[$pos]} to meta ${aa};"
(( metacnt = metacnt + 1 ))
done
metacnt=1
(( pos = pos + 1 ))
done < cusmet.txt
See example output. # ./meta_build.sh form meta from dev 0D20, config=striped; add dev 0D21 to meta 0D20; add dev 0D22 to meta 0D20; add dev 0D23 to meta 0D20; add dev 0D24 to meta 0D20; add dev 0D25 to meta 0D20; add dev 0D26 to meta 0D20; add dev 0D27 to meta 0D20; form meta from dev 0D28, config=striped; add dev 0D29 to meta 0D28; add dev 0D2A to meta 0D28; add dev 0D2B to meta 0D28; DMX HYPERThe "gohype.sh" script gets unused hypers. It requires the "cusreq.txt" file that contains type, size, and qty. This script extracts the hyper definitions and selects unused devices from the array. It displays the devices so that you can check attributes. Note, it appends devices to the hypers.txt file, as you may have created metas and the meta head is stored in this file. Ensure your cusreq.txt file exists. # cat cusreq.txt hyper 3375 10 hyper 30713 8 hyper 61425 4 meta 30713 12 gohype.sh
#!/bin/ksh
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
cc=`echo $LINE | awk '{print $3}'`
if [[ $aa == "hyper" ]]; then
sudo symdev -sid $mysid list -noport | grep $bb | grep -v "(M)" | grep -v "WD" | awk '{print $1}' | head -n $cc >> hypers.txt
fi
done < cusreq.txt
for i in `cat hypers.txt`
do
echo $i
sudo symdev -sid $mysid show $i | egrep '(Mega|FA |WD|Configuration|RDF|SCSI-3 Persistent| N/A)'
echo ""
done
See output from script. # cat hypers.txt 0D20 * meta device (see DMX META) 0D28 * meta device (see DMX META) 1FAE 1FB8 0261 0262 0263 0264 0265 0266 0267 0268 0269 026A 1FBD 1FBE 1FBF 1FC0 1FC1 1FC2 1FC3 1FC4 2571 2572 DMX MAPThis script builds a "mapping file" file using user defined FAs and ports. Ensure your hypers.txt file and hostfa.txt exist. # cat hypers.txt 0D20 0D28 ... # cat hostfa.txt (this host is using 4 FA's) 07b 0 08b 0 09b 0 10b 0 map_file.sh builds a map file from a list on unused addresses.
#!/bin/ksh
typeset -i cnt
# Check each FA has same next starting address.
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
#cnt=`sudo symcfg -sid $mysid list -fa $aa -p $bb -address -available | grep "Mapped Devices" | awk '{print $3}'`
tmp=`sudo symcfg -sid $mysid list -fa $aa -p $bb -address -available | tail -15 | grep AVAILABLE | awk '{print $5}'`
cnt=$( printf "%d" 0x${tmp} )
#echo $aa $bb $cnt
done < hostfa.txt
# Prepare map file
for i in `cat hypers.txt`
do
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
hex_representation=$( printf "%X" ${cnt} )
echo "map dev ${i} to dir $aa:$bb, lun=${hex_representation};"
done < hostfa.txt
(( cnt = cnt + 1 ))
done
See sample output from script. # ./map_file.sh map dev 0D20 to dir 07b:0, lun=A4; map dev 0D20 to dir 08b:0, lun=A4; map dev 0D20 to dir 09b:0, lun=A4; map dev 0D20 to dir 10b:0, lun=A4; map dev 0D28 to dir 07b:0, lun=A5; map dev 0D28 to dir 08b:0, lun=A5; map dev 0D28 to dir 09b:0, lun=A5; map dev 0D28 to dir 10b:0, lun=A5; DMX MASKA list of scripts used during the MASK procedure. # cat hosts.txt (example) USTPA3IFSVM073 USTPA3IFSVM074 USTPA3IFSVM075 USTPA3IFSVM076 USTPA3IFSVM077 # cat hostfa.txt (this host is using 2 FA's) 10d 1 07d 1 create_vcm.sh to prepare hostvcm.txt file. Requires host logged into FA and VCM DB labeled.
#!/bin/ksh
for i in `cat hosts.txt`
do
while IFS= read LINE
do
myfa=`echo $LINE | awk '{print $1}'`
mypt=`echo $LINE | awk '{print $2}'`
sudo symmask -sid $mysid -dir $myfa -p $mypt list logins > t.t
grep $i t.t | awk '{print $1 "\t" "'$myfa'" "\t" "'$mypt'" "\t" $4 "\t" $3}'
done < hostfa.txt
done
Sample output. 10000000c97428ab 10D 1 HBA0 USTPA3IFSVM073 10000000c97450bb 07D 1 HBA1 USTPA3IFSVM073 10000000c97431ff 07D 1 HBA1 USTPA3IFSVM074 10000000c97e04c1 10D 1 HBA0 USTPA3IFSVM074 10000000c9742bd2 10D 1 HBA0 USTPA3IFSVM075 10000000c9745195 07D 1 HBA1 USTPA3IFSVM075 10000000c97451b8 07D 1 HBA1 USTPA3IFSVM076 10000000c97460c2 10D 1 HBA0 USTPA3IFSVM076 10000000c97450b9 07D 1 HBA1 USTPA3IFSVM077 10000000c97461b3 10D 1 HBA0 USTPA3IFSVM077 mydevs.sh to display devs in comma separated format. #!/bin/ksh mydevs="-" for i in `cat hypers.txt` do if [ $mydevs = "-" ]; then mydevs=$i else mydevs=$mydevs,$i fi done Sample output. 0257,0258,0259,025A,0E18,2412,2413,2414,240E mask_file.sh to create a file used for masking VCM DB.
#!/bin/ksh
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
cc=`echo $LINE | awk '{print $3}'`
echo "sudo symmask -sid $mysid -wwn $aa -dir $bb -p $cc add dev $mydevs"
echo "sleep 1"
done < hostvcm.txt
Sample output. sudo symmask -sid 4145 -wwn 10000000c943e6fd -dir 07B -p 0 add dev 0257,0258,0259,025A,0E18,2412,2413,2414,240E sleep 1 sudo symmask -sid 4145 -wwn 10000000c943e64f -dir 07B -p 0 add dev 0257,0258,0259,025A,0E18,2412,2413,2414,240E sleep 1 sudo symmask -sid 4145 -wwn 10000000c943e6fc -dir 10B -p 0 add dev 0257,0258,0259,025A,0E18,2412,2413,2414,240E sleep 1 sudo symmask -sid 4145 -wwn 10000000c943e64e -dir 10B -p 0 add dev 0257,0258,0259,025A,0E18,2412,2413,2414,240E sleep 1 mask_check.sh to confirm matching masking entries on HBAs
#!/bin/ksh
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
cnt=`sudo symmaskdb -sid $mysid -wwn $aa list devs | wc -l`
echo $cnt
done < hostvcm.txt
Sample output. 174 174 174 174 mask_label.sh to label VCM DB.
#!/bin/ksh
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
cnt=`sudo symmaskdb -sid $mysid -wwn $aa list devs | wc -l`
echo $cnt
done < hostvcm.txt
mask_display.sh to display disk information.
#!/bin/ksh
echo "DevID MB Raid Meta Hex LUN Addresses"
for i in `cat hypers.txt`
do
addr=`sudo symdev -sid $mysid show $i | grep "FA " | awk '{print $9}'`
mega=`sudo symdev -sid $mysid show $i | grep "MegaBytes" | awk '{print $3}'`
raid=`sudo symdev -sid $mysid show $i | grep "Device Configuration" | awk '{print $4}'`
meta=`sudo symdev -sid $mysid show $i | grep "Meta Configuration" | awk '{print $4}'`
if [[ $meta != "Striped" ]]; then
meta="n/a"
fi
printf "%-10s %10s %10s %10s %6s %6s %6s %6s\n" $i $mega $raid $meta $addr
done
Sample output. DevID MB Raid Meta Hex LUN Addresses 0257 3375 2-Way n/a 0A4 0A4 0258 3375 2-Way n/a 0A5 0A5 0259 3375 2-Way n/a 0A6 0A6 025A 3375 2-Way n/a 0A7 0A7 0E18 30713 RAID-5 n/a 0A8 0A8 2412 61425 RAID-5 n/a 0A9 0A9 2413 61425 RAID-5 n/a 0AA 0AA 2414 61425 RAID-5 n/a 0AB 0AB 240E 245700 RAID-5 Striped 0AC 0AC DMX DECOMvcm_remove.sh
#!/bin/ksh
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
cc=`echo $LINE | awk '{print $3}'`
echo "sudo symmask -sid $mysid -wwn $aa -dir $bb -p $cc delete -login"
done < hostvcm.txt
lun_dis.sh
#!/bin/ksh
for i in `cat hypers.txt`
do
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
echo "sudo symdev -sid $mysid write_disable $i -sa $aa -p $bb -noprompt"
echo "sleep 1"
done < hostfa.txt
done
lun_wrt.sh - in case you need to roll back.
#!/bin/ksh
for i in `cat hypers.txt`
do
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
echo "sudo symdev -sid $mysid rw_enable $i -sa $aa -p $bb -noprompt"
echo "sleep 1"
done < hostfa.txt
done
unmap_file.sh
#!/bin/ksh
typeset -i cnt
# Prepare unmap file
for i in `cat hypers.txt`
do
while IFS= read LINE
do
aa=`echo $LINE | awk '{print $1}'`
bb=`echo $LINE | awk '{print $2}'`
echo "unmap dev ${i} from dir $aa:$bb;"
done < hostfa.txt
done
SRDF/A CHECKTries to resume from a suspend SRDF/A link.
#!/bin/ksh
#
# SRDF Check: David Spink 03/15/08
#
# If SRDF suspended, set to adaptive copy, try resume, and send mail to SAN team.
# Switching back to Async mode is not performed by script, by design.
#
# Log start time
cat - << HERE
====SRDF check begin `date`
HERE
# Check if previous check script is running
cd /opt/support/home/sanadmin/srdf_check
ps -e | grep srdf_check.sh > /dev/null
if [ $? -eq 0 ]; then
echo "A previous SRDF script is still running....exiting."
/usr/bin/uuencode ./srdf_cron.log ./srdf_cron.log | \
/usr/bin/mailx -s "A previous SRDF check script is still running - open log with wordpad." \
david.r.spink@us.pwc.com
exit
fi
# Check for tranmit idle
mysid=1748
myra=1
while (( myra < 3 ))
do
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -rdfg $myra list | grep "TransIdle" > /dev/null
if [ $? -eq 0 ]; then
#echo "TRUE" > ./acp_mode.txt
echo "SRDF $myra in TransIdle Mode"
/usr/bin/uuencode ./srdf_cron.log ./srdf_cron.log | \
/usr/bin/mailx -s "SRDF $myra in TransIdle Mode - open log with wordpad." \
david.r.spink@us.pwc.com
exit
fi
(( myra = myra +1 ))
done
# Check for any RA group is adaptive copy mode
mysid=1748
myra=1
while (( myra < 3 ))
do
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -rdfg $myra list | grep "C.?" > /dev/null
if [ $? -eq 0 ]; then
echo "TRUE" > ./acp_mode.txt
echo "SRDF $myra in Adaptive Copy Mode"
/usr/bin/uuencode ./srdf_cron.log ./srdf_cron.log | \
/usr/bin/mailx -s "SRDF $myra in Adaptive Copy Mode - open log with wordpad." \
david.r.spink@us.pwc.com
fi
(( myra = myra +1 ))
done
# Check maintenance flag setting
grep TRUE ./acp_mode.txt > /dev/null
if [ $? -eq 0 ]; then
# If needed unset maintenance flag by editing acp_mode.txt and set value to FALSE.
echo "Maintenance flag is set exiting script, check acp_mode.txt"
echo "==== end time `date`"
/usr/bin/uuencode ./srdf_cron.log ./srdf_cron.log | \
/usr/bin/mailx -s "Maintenance flag is set exiting script, check acp_mode.txt - open \
log with wordpad." david.r.spink@us.pwc.com
exit
else
# Maintenance flag is not set, hence ./acp_mode.txt set to false.
echo "Maintenance mode is not active, hence proceeding to check RA groups."
fi
# Check RA groups for Suspend
mysid=1748
myra=1
while (( myra < 3 ))
do
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -rdfg $myra list | grep Suspend > /dev/null
if [ $? -eq 0 ]; then
# list devices in log
echo "RA $myra Suspend State."
# get before picture
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -rdfg $myra list
echo "Attempting to set RA $myra adaptive copy."
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -f ./allr${myra}.txt -rdfg $myra \
set mode acp_disk -noprompt -c 2 -i 120
echo "Attempting to resume RA $myra."
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -f ./allr${myra}.txt -rdfg $myra \
resume -noprompt -c 2 -i120
echo "Manually check SRDF and set back to Async mode."
# get after picture
/usr/local/bin/sudo /usr/symcli/bin/symrdf -sid $mysid -rdfg $myra list
echo "SRDF check script is disabled until maintenance flag turned off - see ./acp_mode.txt."
echo "TRUE" > ./acp_mode.txt
else
echo "RA $myra is not suspended."
fi
(( myra = myra +1 ))
done
echo "==== end time `date`"
# Send email
grep TRUE ./acp_mode.txt > /dev/null
if [ $? -eq 0 ]; then
# Link in adaptive copy or maintenance mode, either way send message
/usr/bin/uuencode ./srdf_cron.log ./srdf_cron.log | /usr/bin/mailx -s "SRDF Needs Checking - \
open log with wordpad." david.r.spink@us.pwc.com
fi
EMC BCV BACKUPPerform a variety of BCV backup operations.
#!/bin/ksh
#
# Script: BCV Backups
#
# Change: David Spink
# Date: May 05, 2004
# Version: 1.3
# REASON : Disabled failure mail notifications and they now form part of netsaint
# Added additional helpful descriptions for running the script
#
# Example: ./bcv_backup.sh -h
#
# Modules: 0. Test conditions, set variables, call modules
# 1. Remesh server vfstab file, create backup file list
# 2. Umount BCV file system, if mounted
# 3. Check BCV state
# 4. Sync BCV & Check status of symmir cmd
# 5. Check progress of sync
# 6. Put database tablespaces in hot backup(online) mode
# 7. Split BCV i.e. no symlocks exist
# 8. Remove database tablespaces from hot backup(online) mode
# 9. Import Disk Group, Start Volumes, Fsck Volumes
# 10. Mount BCV file systems
# 11. Backup BCV's
# 12. Umount BCV File Systems and Deport Disk Group
#
#=== Build an array of mount points ===
#
buildMPV()
{
echo "=== Step 1. Remesh $Server vfstab file ===";echo
#move any previous mount point server file to an archive directory
mv $WorkDir/server_mnts/$Server.$myDB.include $WorkDir/server_mnts/old/$Server.$myDB.include.${MyDate} 2> /dev/null
#archive log files
for LOGFILE in `find $WorkDir/logs/* -type d -prune -o -mtime +1 -print`
do
mv $LOGFILE $WorkDir/logs/old_logs
done
#set variable attributes
cnt=0
#rshell to server and get list of mount points
echo "List volume and mount points for disk group on $Server"
for MPOINT in `remsh $Server cat /etc/vfstab | grep $VxdGp | awk '{print $3}'`
do
#increment counter
(( cnt = cnt +1 ))
#place each mount point into an array of elements
my_mpoint[$cnt]=$MPOINT
#place corresponding volume into an array of elements
my_mvolum[$cnt]=`remsh $Server cat /etc/vfstab | grep " ${my_mpoint[$cnt]} " | awk '{print $1}'`
#display the mount points collected
echo $cnt"." ${my_mvolum[$cnt]} ${my_mpoint[$cnt]}
#make directory on backup server
mkdir -p ${my_mpoint[$cnt]}
#send the mount points to file, used for backup file list
echo ${my_mpoint[$cnt]} >> $WorkDir/server_mnts/$Server.$myDB.include
done
echo
#check if mount point build worked
if [ $cnt = "0" ]; then
#build list of mount points failed
echo "Aborting Backup...remsh failed, or no veritas disk group"
exit
else
#display backup file list
echo "Netbackup include file -> $WorkDir/server_mnts/$Server.$myDB.include"
cat $WorkDir/server_mnts/$Server.$myDB.include
fi
echo;echo
return
}
#
# === Umount file systems, if mounted ===
#
umountMP()
{
echo "=== Step 2. Umount BCV file systems, if mounted ===";echo
#check for existing bcv mount point
# num=0;testm=false
testm=false; num=cnt+1
# while (( num < cnt ))
while (( num > 1 ))
do
# (( num = num +1 ))
(( num = num -1 ))
#for each mount collected in step 1, check to see if it's mounted
df -k | grep ${my_mpoint[$num]}
if [ $? -eq 0 ]; then
#mount points exists, gracefully try to umount the file system
umount ${my_mpoint[$num]}
if [ $? -eq 1 ]; then
#umount failed, find out what process is using mount point
echo "Running fuser -cu ${my_mpoint[$num]}"
fuser -cu ${my_mpoint[$num]}
echo "Aborting Backup...cannot umount BCV mount point"
exit
else
echo "umount ${my_mpoint[$num]} successfull"
testm=true
fi
fi
done
if [ $testm = "false" ]; then
#this means no bcv file system were mounted
echo "No file systems were mounted"
fi
#check if veritas disk group is imported, if so deport
vxdg list | grep $VxdGp > /dev/null
if [ $? -eq 0 ]; then
#stop and deport veritas disk group
echo;echo "Stopping and Deporting veritas disk group $VrtDg"
vxvol -g $BcvDg stopall
vxdg deport $VxdGp
if [ $? -eq 1 ]; then
#vxdg deport failed
echo "Aborting Backup...cannot deport $VxdDg"
exit
fi
fi
echo;echo
return
}
#
# === Check BCV state ===
#
symmirSTATE()
{
echo "=== Step 3. Check BCV symmir status ===";echo
#Check to see if the BCV disk group is in any other state other than split
echo "Check $BcvDg symmir status"
$SymDir/symmir -g $BcvDg query | egrep '(Synchronized|SyncInProg)'
if [ $? -eq 0 ]; then
#there are problems with bcv status
echo
echo "Aborting Backup...BCV $BcvDg is not split"
#echo "Aborting Backup...BCV $BcvDg is not split" | mailx -s "$Location BCV scripts $Server Error" $MyEmail
exit
else
#there aren't any problems with bcv status
echo "BCV $BcvDg is not currently being sync'd"
fi
echo;echo
return
}
#
# === Sync BCV ===
#
symmirCMD()
{
echo "=== Step 4. Performing symmir cmd ===";echo
echo "Running $SymDir/symmir -g $BcvDg establish -noprompt -$IncFull"
$SymDir/symmir -g $BcvDg establish -noprompt -$IncFull
#$SymDir/symmir -g $BcvDg establish -noprompt -force -full
sleep 10
echo "Wait 10 seconds, check BCV SyncInProg"
$SymDir/symmir -g $BcvDg query | grep SyncInProg
if [ $? -eq 0 ]; then
#symmir cmd is working
echo "BCV $BcvDg symmir is working"
else
#symmir cmd is not working
echo "Aborting Backup...BCV $BcvDg symmir failed."
exit
fi
echo;echo
return
}
#
# === Check status of symmir cmd"
#
symmirCHK()
{
echo "=== Step 5. Waiting until symmir sync cmd ends ===";echo
#wait until symmir cmd completes
num=0
while [ $num -eq 0 ]
do
$SymDir/symmir -g $BcvDg query | grep SyncInProg > /dev/null
if [ $? -eq 1 ]; then
#sync is complete, show results
$SymDir/symmir -g $BcvDg query | grep SyncInProg
#sync is complete, set loop exit condition
num=1
else
#sync is not complete
echo "Sync in progress `date`, check interval 2 minutes"
sleep 120
fi
done
echo ""
return
}
#
# === Put Tablespaces in Backup Mode ===
#
tblspcBKUP()
{
echo "=== Step 6. Put Tablespaces in Backup Mode ==="
echo "Running alter tablespace backup for $myDB"
. /usr/local/bin/ora${myDB}
rm -f /tmp/${myDB}.tablespaces
#
sqlplus -s ${bkupLogin}@${myDB} <
EMC OTHERCron Entries 30 05 * * * /opt/san_4145/vcm/vcm_bck.sh > /opt/san_4145/vcm/vcm_bck.log 2>&1 30 23 * * * /opt/san_4145/nar/narget.sh > /opt/san_4145/nar/narget.log 2>&1 30 04 * * * /opt/san_4145/logins/vcm_logins.sh > /opt/san_4145/logins/vcm_logins.log 2>&1 vcm_bck.sh
cat vcm_bck.sh
#!/bin/ksh
# Log start time
echo "====VCM Backup Start `date`"
cd /opt/san_4145/vcm
#
myDate=`/usr/bin/date +%Y-%m-%d`
#
# Perform Backup
for i in `cat ./myarray.txt`
do
mv -f ./${i}_vcm.txt ./history/${i}_vcm.txt.${myDate} 2> /dev/null
mv -f ./${i}_vcm.db ./history/${i}_vcm.db.${myDate} 2> /dev/null
echo "List database ${i}_vcm.txt"
/usr/local/bin/sudo /usr/symcli/bin/symmaskdb -sid $i list database > ${i}_vcm.txt
echo "Backup database ${i}_vcm.db"
/usr/local/bin/sudo /usr/symcli/bin/symmaskdb -sid $i -file ${i}_vcm.db backup -noprompt
done
echo ""
vcm_logins.sh
#!/bin/ksh
# Log start time
echo "====VCM Logins Start `date`"
cd /opt/san_4145/logins
#
myDate=`/usr/bin/date +%Y-%m-%d`
#
# Get VCM Logins
for i in `cat ./myarray.txt`
do
mv -f ./${i}_logins.txt ./history/${i}_logins.txt.${myDate} 2> /dev/null
echo "List ${i}_logins.txt"
/usr/local/bin/sudo /usr/symcli/bin/symmask -sid $i list logins > ${i}_logins.txt
done
echo ""
narget.sh
#!/bin/ksh
# Log start time
echo "====NAR Get Start `date`"
cd /opt/san_4145/nar
#
myDate=`/usr/bin/date +%Y-%m-%d`
# Get NAR
for i in `cat ./myarray.txt`
do
echo $i
mv ./${i}_spa.nar ./history/${i}_spa.nar.${myDate} 2> /dev/null
mv ./${i}_spb.nar ./history/${i}_spb.nar.${myDate} 2> /dev/null
/opt/Navisphere/bin/naviseccli -h ${i}_spa analyzer -archiveretrieve -file ${i}_spa.nar
/opt/Navisphere/bin/naviseccli -h ${i}_spb analyzer -archiveretrieve -file ${i}_spb.nar
done
gethost-cx.sh
#!/bin/ksh
# Log start time
echo "====Get CX Hosts"
#
myDate=`/usr/bin/date +%Y-%m-%d`
# Get NAR
for i in `cat ./myarray.txt`
do
echo $i
navicli -h ${i}_spa storagegroup -list -host > host_${i}.txt
cat host_${i}.txt | grep "Host name:" | awk '{print $3}' | sort | uniq > $1-hostonly.txt
done
makelun.sh
for id in `cat t.txt`
do
echo $id
navicli -h 2311_spa bind r5 ${id}0 -rg ${id} -rc 1 -wc 1 -sp a -sq GB -cap 200
navicli -h 2311_spb bind r5 ${id}1 -rg ${id} -rc 1 -wc 1 -sp b -sq GB -cap 200
navicli -h 2311_spa bind r5 ${id}2 -rg ${id} -rc 1 -wc 1 -sp a -sq GB -cap 100
navicli -h 2311_spb bind r5 ${id}3 -rg ${id} -rc 1 -wc 1 -sp b -sq GB -cap 100
navicli -h 2311_spa bind r5 ${id}4 -rg ${id} -rc 1 -wc 1 -sp a -sq GB -cap 100
navicli -h 2311_spb bind r5 ${id}5 -rg ${id} -rc 1 -wc 1 -sp b -sq GB -cap 100
navicli -h 2311_spa bind r5 ${id}6 -rg ${id} -rc 1 -wc 1 -sp a -sq GB -cap 50
navicli -h 2311_spb bind r5 ${id}7 -rg ${id} -rc 1 -wc 1 -sp b -sq GB -cap 50
navicli -h 2311_spa bind r5 ${id}8 -rg ${id} -rc 1 -wc 1 -sp a -sq GB -cap 50
navicli -h 2311_spb bind r5 ${id}9 -rg ${id} -rc 1 -wc 1 -sp b -sq bv -cap 49248768
done
allocated.sh
sudo symdev -sid $1 list -FA all | tail +10> t.t
x=`cat t.t | cut -c70- | awk '{total += $2 } END { print total }'`
(( x = $x / 1024 ))
echo $x
unallocated.sh
sudo symdev -sid $1 list -noport | tail +10> t.t
x=`cat t.t | cut -c70- | awk '{total += $2 } END { print total }'`
(( x = $x / 1024 ))
echo $x
EMC SYMLDLoad new devices into sym group.
# cat add.txt
0C28
0C29
0E1E
0E1F
0E20
...
z=DEV
typeset -i cnt
cnt=151
for i in `cat add.txt`
do
(( cnt = cnt +1 ))
a=DEV$cnt
#echo "sudo symld -g sapgfstgt add dev $i $a -sid 1748"
sudo symld -g sapgfstgt add dev $i $a -sid 1748
done
# cat x.x
8D8
8E0
8E4
8E8
8EC
8F0
8F4
8F8
echo "1 000190101384" > yy.txt
z=DEV
typeset -i cnt
cnt=0
for i in `cat t.txt`
do
(( cnt = cnt +1 ))
if (( $cnt < 10 )); then
a=DEV00$cnt
else
if (( $cnt < 100 )); then
a=DEV0$cnt
else
a=DEV$cnt
fi
fi
echo "S $i $a"
done
WD CHECKCheck if any write disabled devices exist on FA's.
#!/bin/ksh
#
# Device WD Check: David Spink 03/15/08
#
# Log start time
echo "====WD Check Start `date`"
cd /opt/san_mgnt/drs/check
#
# Check WD on FA Ports
for i in `cat ./myarray.txt`
do
echo "/usr/symcli/bin/symdev -sid $i -SA ALL -P 0 list | grep WD | grep -v VCM"
/usr/local/bin/sudo /usr/symcli/bin/symdev -sid $i -SA ALL -P 0 list | grep WD | grep -v VCM
if [ $? -eq 0 ]; then
/usr/bin/uuencode ./portswd.log ./portswd.log | /usr/bin/mailx -s "WD Disks on $i, Port 0" \
david.r.spink@us.pwc.com
else
echo "no WD devices"
fi
#
echo "/usr/symcli/bin/symdev -sid $i -SA ALL -P 1 list | grep WD | grep -v VCM"
/usr/local/bin/sudo /usr/symcli/bin/symdev -sid $i -SA ALL -P 1 list | grep WD | grep -v VCM
if [ $? -eq 0 ]; then
/usr/bin/uuencode ./portswd.log ./portswd.log | /usr/bin/mailx -s "WD Disks on $i, Port 1" \
david.r.spink@us.pwc.com
else
echo "no WD devices"
fi
done
echo ""
Crontab entry. # Check array FA ports for write disabled 55 23 * * * /opt/san_mgnt/drs/check/portswd.sh 1>> /opt/san_mgnt/drs/check/portswd.log 2>&1 EMC USEDStorage Management Reports, replaced by Control Centre. This was one of my first scripts when learning KSH.. good memories.
#!/bin/ksh
#
# Author: David Spink Sep 30, 2003
#
# Storage Management Report
#
# Section 1: Declare Variables - site etc.
# Section 2: Summary Allocations
# Section 3: EMC Summary of Disk Usage
# Section 4: DAS Summary of Disk Usage
# Section 5: Combined DAS & SAN Summary
# Section 6: EMC Spare Allocated Disks
# Section 7: EMC Non Allocated Disks
# Section 8: EMC Non Allocated BCVs
# Section 9: EMC Sym & OS Device ID Configs #
# Section 10: EMC SAN Host with breakdown of disk/group allocation
#####################################
# Section 0: Check parameters #
#####################################
#check that you are user root
id | grep root > /dev/null
if [ $? -ne 0 ]; then
echo "You must be user root to execute $0"
exit
fi
#check parameters are passed
if [ $1 != "d1" -a $1 != "d2" ]; then
cat - << HERE
NAME
storage.sh - for reporting on EMC storage allocations and configuration
SYNOPSIS
storage.sh { d1 | d2 }
DESCRIPTION
The storage script provides summary allocations per host of EMC storage, shows disk usage
for SAN and direct-attached, lists any spare allocated devices, lists any spare non
allocated devices, reports on EMC sym device id's and SOLARIS device id's and provides a
breakdown on EMC hosts and percentages of disk utilisation.
OPTIONS
d1 - used for data centre 1, Tampa
d2 - used for data centre 2, UK
HERE
exit
fi
####################################
# Section 1: Declare Variables #
#####################################
if [ $1 = "d1" ]; then
SITENAME=Tampa
else
SITENAME=UK
fi
SYMSRV=$1pr0009 #symcli server, for UK enter d2pre000
SITE=$1 #replace d1 with d2
SERVER_ALL=servers_nonemc_$1 #file containing all non emc servers
SITEVAR=tc #if there are other servers without std d1 or d2 prefix, eg tpahype3, c1pr0001
HYP_SIZ=9 #size of hype
HYP_STD=`remsh $SYMSRV /usr/symcli/bin/symdev -nobcv list | grep 8632 | wc -l` #number of STD's
HYP_BCV=`remsh $SYMSRV /usr/symcli/bin/symdev -bcv list | grep 8632 | wc -l` #number of BCV's
cd /app/emc-scripts
#####################################
# Section 2: Summary Allocations #
#####################################
cat - << HERE
$SITENAME - Storage Report
Author: David Spink
Date : `date`
------------------------------------------------------------------------------------------
EMC Equipment Summary
------------------------------------------------------------------------------------------
HERE
remsh $SYMSRV /usr/symcli/bin/symcfg -v list
cat - << HERE
------------------------------------------------------------------------------------------
EMC SAN Summary Allocations
------------------------------------------------------------------------------------------
No.M1 number of EMC 9Gb (hypers) disks
M1 GB amount of EMC disk useable by host in GigaBytes
No.BCV number of EMC backup contingency disks
BCV GB amount of BCV disk in GigaBytes
No.R1 number of R1 replication disks assigned
R1 GB amount of R1 disk in GigaBytes
Allocated sum of columns, e.g. total allocated M1 (useable disks) for all hosts
Un-Allocated how much storage has NOT been assigned via ESN_Manager
No.9Gb Hypers sum of hypers allocated & un-allocated - total right column
Total Useable sum of useable disk for M1, BCV and R1. Equals "No.9Gb Hypers" * 9Gb
Total Raw sum of raw disk for M1(non-mirrored), BCV and R1
FS Vol. 18Gb 1*9Gb (mirrored) hyper is used by EMC internally
Hostname No.M1 M1 GB No.BCV BCV GB No.R1 R1 GB Totals
HERE
#
# Get M1 and BCV allocated to each host
#
for SERVER in `cat ./servers_emc | grep -v "^#" | grep $SITE`
do
# run symcfg discover to catch any new drives added under veritas control
remsh $SERVER /usr/symcli/bin/symcfg discover > /dev/null
# count hypers per host
M1=`remsh $SERVER /usr/symcli/bin/symdev -nobcv list | grep /dev/vx | grep 8632 | wc -l`
# total allocation of M1 storage
(( M1GB=$M1 * $HYP_SIZ))
# number of bcvs assigned to host
BCV=`remsh $SYMSRV /usr/symcli/bin/symdg list | tail +7 | sed 's/^....//' | sort -n | tail +2 | \
awk '{printf("%-20s %-5s\n", $1, $7) }' | grep $SERVER | awk '{ total += $2 } END { print total }'`
# total allocation of BCV storage
(( BCVGB=$BCV * $HYP_SIZ ))
# number of r1 assigned to host, to keep this simply in version 1 i'm not trying to calc r1s to hosts
R1=0
# total allocation of R1 storage
(( R1GB=$R1 * $HYP_SIZ ))
# print out results
printf "%-15s %3s %10s %10s %10s %10s %10s\n" $SERVER $M1 $M1GB $BCV $BCVGB $R1 $R1GB
# sum of allocated m1, bcvs, r1s
(( SUM_M1=$SUM_M1 + $M1 ))
(( SUM_M1GB=$SUM_M1GB + $M1GB ))
(( SUM_BCV=$SUM_BCV + $BCV ))
(( SUM_BCVGB=$SUM_BCVGB + $BCVGB ))
(( SUM_R1=$SUM_R1 + $R1 ))
(( SUM_R1GB=$SUM_R1GB + $R1GB ))
done
#
# print sum of allocated m1, bcvs, r1s
#
echo " --- --- --- --- --- ---"
printf "%-15s %3s %13s %7s %13s %7s %13s %10s\n" \
"Allocated" $SUM_M1 $SUM_M1GB" Gb" $SUM_BCV $SUM_BCVGB" Gb" $SUM_R1 $SUM_R1GB" Gb"
#
# determine number of un-allocated m1s, bcvs and print
#
(( UN_M1=$HYP_STD - $SUM_M1 ))
(( UN_M1GB=$UN_M1 * $HYP_SIZ ))
(( UN_BCV=$HYP_BCV - $SUM_BCV ))
(( UN_BCVGB=$UN_BCV * $HYP_SIZ ))
(( UN_R1=0 - $SUM_R1 ))
(( UN_R1GB=$UN_R1 * $HYP_SIZ ))
printf "%-15s %3s %13s %7s %13s %7s %13s %10s\n" \
"Un-Allocated" $UN_M1 $UN_M1GB" Gb" $UN_BCV $UN_BCVGB" Gb" $UN_R1 $UN_R1GB" Gb"
echo " --- --- --- --- --- ---"
#
# determine totals for m1s, bcvs and print
#
(( TOT_M1=$SUM_M1 + $UN_M1 ))
(( TOT_M1GB=$SUM_M1GB + $UN_M1GB ))
(( TOT_BCV=$SUM_BCV + $UN_BCV ))
(( TOT_BCVGB=$SUM_BCVGB + $UN_BCVGB ))
(( TOT_R1=$SUM_R1 + $UN_R1 ))
(( TOT_R1GB=$TOT_R1 * $HYP_SIZ ))
(( TOT_COOK=$TOT_M1GB + $TOT_BCVGB + $TOT_R1GB ))
(( TOT_ALLO=$SUM_M1GB + $TOT_BCVGB + $TOT_R1GB ))
(( TOT_HYPER=$TOT_M1 + $TOT_BCV + $TOT_R1 ))
printf "%-15s %3s %21s %21s %18s %11s\n" "No.9Gb Hypers" $TOT_M1 $TOT_BCV $TOT_R1 "=" $TOT_HYPER" Hypers"
if [ $SITE = d1 ]; then
printf "%-25s %6s %21s %21s %4s %7s\n" "Total Useable " $TOT_M1GB" Gb" $TOT_BCVGB" Gb" $TOT_R1GB" Gb" "=" $TOT_COOK" Gb"
else
printf "%-25s %7s %21s %21s %4s %7s\n" "Total Useable " $TOT_M1GB" Gb" $TOT_BCVGB" Gb" $TOT_R1GB" Gb" "=" $TOT_COOK" Gb"
fi
#
# determine raw disk space for m1s, bcvs and print
#
(( RAW_M1GB=$TOT_M1GB * 2 ))
(( TOT_RAW=$RAW_M1GB + $TOT_BCVGB + $TOT_R1GB))
printf "%-25s %7s %21s %21s %4s %7s\n" "Total Raw " $RAW_M1GB" Gb" $TOT_BCVGB" Gb" $TOT_R1GB" Gb" "=" $TOT_RAW" Gb"
printf "\n"
#######################################
# Section 3: EMC Summary Disk Usage #
#######################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC Summary of Disk Usage
------------------------------------------------------------------------------------------
EMC is divided into 9Gb Hypers hence the first set of totals show the amount useable.
In practice though only 8.4Gb of this 9Gb is useable, hence second set of true totals.
The third section show how much is being allocated, amount used and amount available.
HERE
#
# calculate practical EMC disk allocations i.e. 8.4G rather than 9Gb
#
TOT_EMCM=$(echo "scale=2; $TOT_M1 * 8.40" | bc)
TOT_EMCA=$(echo "scale=2; $SUM_M1 * 8.40" | bc)
TOT_EMCU=$(echo "scale=2; $UN_M1 * 8.40" | bc)
#
# calculate disk usage a file system level
#
for SERVER in `cat ./servers_emc | grep -v "^#" | grep $SITE`
do
(( ETOT_BYTE=$ETOT_BYTE + `remsh $SERVER df -k | grep /vol* | awk '{ total += $2 } END { print total }'` ))
(( ETOT_USED=$ETOT_USED + `remsh $SERVER df -k | grep /vol* | awk '{ total += $3 } END { print total }'` ))
(( ETOT_AVAL=$ETOT_AVAL + `remsh $SERVER df -k | grep /vol* | awk '{ total += $4 } END { print total }'` ))
done
ETOT_BYTE=$(echo "scale=2; $ETOT_BYTE / 1048576" | bc)
ETOT_USED=$(echo "scale=2; $ETOT_USED / 1048576" | bc)
ETOT_AVAL=$(echo "scale=2; $ETOT_AVAL / 1048576" | bc)
TOT_M1GB=$(echo "scale=2; $TOT_M1GB + .00" | bc)
SUM_M1GB=$(echo "scale=2; $SUM_M1GB + .00" | bc)
UN_M1GB=$(echo "scale=2; $UN_M1GB + .00" | bc)
#
# print emc summary of disk usage
#
if [ $SITE = d1 ]; then
printf "%-50s %2s %9s\n" "Total EMC disk @9Gb LUNs (theoretical max)" "=" $TOT_M1GB" Gb"
printf "%-50s %2s %9s\n" "Total amount of disk allocated @9Gb" "=" $SUM_M1GB" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk un-allocated @9Gb" "=" $UN_M1GB" Gb"
printf "\n"
printf "%-50s %2s %9s\n" "Total EMC disk @8.4Gb LUNS allocated (actual max)" "=" $TOT_EMCM" Gb"
printf "%-50s %2s %9s\n" "Total amount of disk allocated @8.4Gb" "=" $TOT_EMCA" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk un-allocated @8.4Gb" "=" $TOT_EMCU" Gb"
printf "\n"
printf "%-50s %2s %9s\n" "Total amount of file system allocated" "=" $ETOT_BYTE" Gb"
printf "%-50s %2s %10s\n" "Total amount of file system used" "=" $ETOT_USED" Gb"
printf "%-50s %2s %10s\n" "Total amount of file system available" "=" $ETOT_AVAL" Gb"
printf "\n"
else
printf "%-50s %2s %10s\n" "Total EMC disk @9Gb LUNs (theoretical max)" "=" $TOT_M1GB" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk allocated @9Gb" "=" $SUM_M1GB" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk un-allocated @9Gb" "=" $UN_M1GB" Gb"
printf "\n"
printf "%-50s %2s %10s\n" "Total EMC disk @8.4Gb LUNS allocated (actual max)" "=" $TOT_EMCM" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk allocated @8.4Gb" "=" $TOT_EMCA" Gb"
printf "%-50s %2s %10s\n" "Total amount of disk un-allocated @8.4Gb" "=" $TOT_EMCU" Gb"
printf "\n"
printf "%-50s %2s %10s\n" "Total amount of file system allocated" "=" $ETOT_BYTE" Gb"
printf "%-50s %2s %10s\n" "Total amount of file system used" "=" $ETOT_USED" Gb"
printf "%-50s %2s %10s\n" "Total amount of file system available" "=" $ETOT_AVAL" Gb"
printf "\n"
fi
#######################################
# Section 4: DAS Summary Disk Usage #
#######################################
cat - << HERE
------------------------------------------------------------------------------------------
Direct Attached Storage (non SAN storage)
------------------------------------------------------------------------------------------
This means all storage that is not EMC within the data centre.
The scripts excludes EMC disks, /proc /fd /mnttab /var/run /cdrom and any NFS mounts
HERE
for SERVER in `cat ./$SERVER_ALL | grep -v "^#"`
do
ping $SERVER > /dev/null 2>&1
if [ $? -eq 0 ]; then
(( DTOT_BYTE=$DTOT_BYTE + `remsh $SERVER df -k | sed -f storage.sed | awk '{ total += $2 } END { print total }'` ))
(( DTOT_USED=$DTOT_USED + `remsh $SERVER df -k | sed -f storage.sed | awk '{ total += $3 } END { print total }'` ))
(( DTOT_AVAL=$DTOT_AVAL + `remsh $SERVER df -k | sed -f storage.sed | awk '{ total += $4 } END { print total }'` ))
else
echo "Server $SERVER not available"
fi
done
DTOT_BYTE=$(echo "scale=2; $DTOT_BYTE / 1048576" | bc)
DTOT_USED=$(echo "scale=2; $DTOT_USED / 1048576" | bc)
DTOT_AVAL=$(echo "scale=2; $DTOT_AVAL / 1048576" | bc)
printf "%-50s %2s %10s\n" "Total amount of DAS file system allocated" "=" $DTOT_BYTE" Gb"
printf "%-50s %2s %10s\n" "Total amount of DAS file system used" "=" $DTOT_USED" Gb"
printf "%-50s %2s %10s\n" "Total amount of DAS file system available" "=" $DTOT_AVAL" Gb"
printf "\n"
###########################################
# Section 5: Combined DAS & SAN Summary #
###########################################
cat - << HERE
------------------------------------------------------------------------------------------
Combined DAS (Direct Attached Storage) and SAN (EMC Storage)
------------------------------------------------------------------------------------------
This section totals the EMC and NON-EMC disk for the data centre.
HERE
TTOT_BYTE=$(echo "scale=2; $ETOT_BYTE + $DTOT_BYTE" | bc )
TTOT_USED=$(echo "scale=2; $ETOT_USED + $DTOT_USED" | bc )
TTOT_AVAL=$(echo "scale=2; $ETOT_AVAL + $DTOT_AVAL" | bc )
if [ $SITE = d1 ]; then
printf "%-50s %2s %9s\n" "Total amount of data centre file system allocated" "=" $TTOT_BYTE" Gb"
printf "%-50s %2s %10s\n" "Total amount of data centre file system used" "=" $TTOT_USED" Gb"
printf "%-50s %2s %9s\n" "Total amount of data centre file system available" "=" $TTOT_AVAL" Gb"
printf "\n"
else
printf "%-50s %2s %9s\n" "Total amount of data centre file system allocated" "=" $TTOT_BYTE" Gb"
printf "%-50s %2s %10s\n" "Total amount of data centre file system used" "=" $TTOT_USED" Gb"
printf "%-50s %2s %10s\n" "Total amount of data centre file system available" "=" $TTOT_AVAL" Gb"
printf "\n"
fi
###########################################
# Section 6: EMC Spare Allocated Disks #
###########################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC Spare Allocated Standards
------------------------------------------------------------------------------------------
These are EMC disks allocated to a host and not being used, i.e. free disk pool.
Hostname Host DeviceID EMC DeviceID
HERE
cnt=0
for SERVER in `cat ./servers_emc | grep -v "^#" | grep $SITE`
do
# exclude disks in dg's, volume logix db and gatekeepers e.g. c3t0d240s2
for DISKFREE in `remsh $SERVER vxdisk list | egrep -v "DEV" | grep " - " | awk '{print $1}'`
do
aa=`remsh $SERVER /usr/symcli/bin/syminq | grep $DISKFREE | grep rdsk | awk '{print $6}'`
if [[ -z $aa ]]; then
aa="empty"
fi
if [ $aa = "8838720" ]; then
echo $DISKFREE | grep '^c' > /dev/null 2>&1
if [ $? -eq 0 ]; then
(( cnt = cnt + 1 ))
STDID=`remsh $SERVER /usr/symcli/bin/syminq 2>&1 | grep /dev/rdsk/$DISKFREE | awk '{print $5}' | cut -c3,4,5`
printf "%-15s %10s %18s\n" $SERVER $DISKFREE $STDID
fi
fi
done
done
echo "Total = $cnt"
echo
###########################################
# Section 7: EMC Non Allocated Disks #
###########################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC Non Allocated Standards
------------------------------------------------------------------------------------------
These are spare disks not allocated to any host.
These volumes have not been assigned in volume logix.
EMC DeviceID Gb Size
HERE
# lists the devices assigned to the FAs
remsh "$SITE"pr0004 /usr/symcli/bin/fpath lssymmdev -d /dev/rdsk/c2t0d0s2 \
| grep " FB" | grep "8.429" | sort | awk '{print $1}' | uniq > /tmp/t1.txt
# lists the VCMDB contents
remsh "$SITE"pr0004 /usr/symcli/bin/fpath lsdb -d /dev/rdsk/c2t0d0s2 | grep " 0" | sort | uniq > /tmp/t2.txt
cnt=0
for DEVID in `cat /tmp/t1.txt`
do
grep $DEVID /tmp/t2.txt > /dev/null
if [ $? -eq 1 ]; then
(( cnt = cnt + 1 ))
printf "%-15s %2s\n" $DEVID $HYP_SIZ
fi
done
echo "Total = $cnt"
echo
rm /tmp/t1.txt > /dev/null
rm /tmp/t2.txt > /dev/null
###########################################
# Section 8: EMC Non Allocated BCVs #
###########################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC Non Allocated BCV's
------------------------------------------------------------------------------------------
These are spare backup contingency volumes not allocated to any host.
These BCV's have not been assigned to any symcli disk group.
Disk Device DeviceID
HERE
remsh $SYMSRV /usr/symcli/bin/symbcv list | grep "^rdmp/" | grep -v + | grep -v - | awk '{print $1, "\t", $2}'
cnt=`remsh $SYMSRV /usr/symcli/bin/symbcv list | grep "^rdmp/" | grep -v + | grep -v - | wc -l`
echo "Total = $cnt"
echo
##############################################
# Section 9: EMC Sym & OS Device ID Configs #
##############################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC Disk Configurations
------------------------------------------------------------------------------------------
This section is for system administrators, removing the complexity of determining EMC
disk allocations, to operating disk group, symmetrix disk group and their device ID's.
HERE
printf "%-10s %-10s %-5s %-8s %-20s %-12s %-5s %-8s %-15s\n" \
"Host" "Host dev" "emcID" "Ldev" "vdskname" "bcv dev" "bcvID" "Ldev" "bcv diskg"
for SERVER in `cat ./servers_emc | grep -v "^#" | grep $SITE`
do
for OSDISK in `remsh $SERVER vxdisk list | egrep -v "DEV" | sort -k 3 -k 2 | awk '{print $1}'`
do
aa=`remsh $SERVER /usr/symcli/bin/syminq | grep $OSDISK | grep rdsk | awk '{print $6}'`
if [[ -z $aa ]]; then
aa="empty"
fi
if [ $aa = "8838720" ]; then
STDID="-"; STDDEV="-"; VRTDG="-"; BCVDISK="-"; BCVID="-"; BCVDEV="-"; BCVDG="-"
echo $OSDISK | grep '^c' > /dev/null
if [ $? -eq 0 ]; then
# Get sym device ID based on logical OS disk
STDID=`remsh $SERVER /usr/symcli/bin/syminq 2>&1 | grep /dev/rdsk/$OSDISK | awk '{print $5}' | cut -c3,4,5`
# Get std logical device name
STDDEV=`remsh $SYMSRV /usr/symcli/bin/symdev show $STDID | grep "Device Logical Name" | awk '{print $5}'`
if [ "$STDDEV" = "" ];then
STDDEV="-"
fi
# Get veritas disk group name
VRTDG=`remsh $SERVER vxdisk list | grep $OSDISK | awk '{print $4}'`
if [ "$VRTDG" = "" ];then
VRTDG="-"
fi
# Get bcv matching device
BCVID=`remsh $SYMSRV /usr/symcli/bin/symdev show $STDID | grep "Attached BCV Device" | awk '{print $5}'`
if [ "$BCVID" = "N/A" ];then
BCVID="-"
else
# Get bcv logical disk name
BCVDISK=`remsh $SYMSRV /usr/symcli/bin/symdev show $BCVID | grep "Device Physical Name" \
| awk '{print $5}' | cut -c14-`
if [ "$BCVDISK" = "" ];then
BCVDISK="-"
fi
fi
# Get bcv device group name
BCVDG=`remsh $SYMSRV /usr/symcli/bin/symdev show $STDID | grep "Standard (STD) Device Group Name" | awk '{print $7}'`
if [ "$BCVDG" = "" -o "$BCVDG" = "Not/Grouped" ];then
BCVDG="-"
else
# Get bcv logical device name
if [ $BCVID != "-" ]; then
BCVDEV=`remsh $SYMSRV /usr/symcli/bin/symld -g $BCVDG list | grep $BCVID | awk '{print $1}'`
if [ "$BCVDEV" = "N/A" ];then
BCVDEV="-"
fi
fi
fi
printf "%-10s %-10s %-5s %-8s %-20s %-12s %-5s %-8s %-15s\n" \
$SERVER $OSDISK $STDID $STDDEV $VRTDG $BCVDISK $BCVID $BCVDEV $BCVDG
fi
fi
done
printf "\n"
done
##############################################
# Section 10: EMC SAN Host Disk Group #
##############################################
cat - << HERE
------------------------------------------------------------------------------------------
EMC SAN Disk Group Allocations
------------------------------------------------------------------------------------------
This section gathers amount of disk allocated, used and available per EMC host
Server Disk Group Allocated Used Available %Used
HERE
for SERVER in `cat ./servers_emc | grep -v "^#" | grep $SITE`
do
for VXDG in `remsh $SERVER vxdg list | tail +2 | grep -v root | awk '{print $1}'`
do
(( ETOT_BYTE=`remsh $SERVER df -k | grep /$VXDG | awk '{ total += $2 } END { print total }'` ))
(( ETOT_USED=`remsh $SERVER df -k | grep /$VXDG | awk '{ total += $3 } END { print total }'` ))
(( ETOT_AVAL=`remsh $SERVER df -k | grep /$VXDG | awk '{ total += $4 } END { print total }'` ))
ETOT_PERC=$(echo "scale=2; (($ETOT_USED / $ETOT_BYTE)) * 100" | bc)
printf "%-15s %-20s %12s %12s %12s %12s\n" $SERVER $VXDG $ETOT_BYTE $ETOT_USED $ETOT_AVAL $ETOT_PERC
done
printf "\n"
done
##############################################
# Section 12: EMC SYM Disk Group #
##############################################
remsh $SYMSRV /usr/symcli/bin/symdg list
exit
NcFTP USERSetup a new NcFTP User. #!/bin/ksh # Author: David Spink # # Date: June 5, 2003 # # Purpose: Create new ncftp FTP user # # How: ./ftpuser.sh "userid" "groupid" "username" "description" # # check that you are root id | grep root > /dev/null if [ $? -ne 0 ]; then echo "You must be user root to execute $0" exit fi # check parameters are passed if [ $# != 4 ]; then echo echo "Usage: $0 arg1 arg2 arg3 arg4" echo echo "Example: $0 3064 3003 huntrefr 'Hunt Refrigeration'" echo echo " 3064 = uid" echo " 3003 = gid" echo " huntrefr = username" echo " Hunt Refrigeration = description " echo exit fi # check uid parameter falls within UID range if [ $1 -le 3000 ]; then echo echo "EDI FTP accounts are greater than 3000" echo "Check Registration User UID.xls" echo exit fi # check uid parameter is not already used grep $1 /etc/passwd > /dev/null if [ $? -eq 0 ]; then echo "UID already exists, please check Registration User UID doc" exit fi # check gid parameter is Lynx if [ $2 -ne 3003 ]; then echo "GID for EDI FTP accounts should be 3003" exit fi # check username is 8 chars or less if [ `echo $3 | wc -c` -gt 9 ]; then echo "Username is longer than 8 chars, please re-enter" exit fi # check username is not too short if [ `echo $3 | wc -c` -lt 4 ]; then echo "Username is to short, please re-enter" fi # add user echo "adding user.." useradd -u $1 -g $2 -d /export/ftp/pubftp/$3 -m -s /bin/ksh -c "$4" $3 # set home directories and permissions echo "setting home directory permissions.." rm /export/ftp/pubftp/$3/local* rm /export/ftp/pubftp/$3/.profile mkdir /export/ftp/pubftp/$3/as2ptnr mkdir /export/ftp/pubftp/$3/ptnr2as chown -R $3:$2 /export/ftp/pubftp/$3 chmod -R 775 /export/ftp/pubftp/$3 # set shell to /etc/ftponly echo "setting shell to ftponly" passmgmt -m -s /etc/ftponly $3 # addvise user for vi /etc/passwd echo "" echo "account is setup - remaining tasks:" echo " a) set passwd" echo " b) perform an ftp test" echo " c) send username, password and output of FTP test to requestor" echo "" NETB RESTOREFor restores first suspend the tape to prevent a backup from writing data onto the tape. Secondly place the media into a pool that won't be ejected during a vault session. The suspend command allows the tape to form part of the scratch pool once the expiration date is reached, whereas a freeze would prevent that from happening. Once the restore is complete move the media into a pool that forms part of vault ejects. The scripts below perform that task. A script is included below the peforms the required functions for moving into a non vault pool.
#!/bin/ksh
# Author: David Spink
#
# Date: Aug 02, 2007
#
# Purpose: Suspend media prior to restore and move tapes into non eject pool
#
# How: ./restore_pre.sh "mediaid"
#
# check that you are root
id | grep root > /dev/null
if [ $? -ne 0 ]; then
echo "You must be user root to execute $0"
exit
fi
# check parameters are passed
if [ $# -ne 1 ]; then
echo
echo "Usage: $0 mediaID"
echo
echo "Example: $0 713551"
echo
echo
exit
fi
# check media ID is 6 chars or less, note wc counts EOL hence value set to 7
if [ `echo $1 | wc -c` -gt 7 ]; then
echo "Media is longer than 6 chars, please re-enter"
exit
fi
# set variable
MEDIA=$1
# suspend media
aa=`bpmedialist -L -m $MEDIA | grep "Server Host" | cut -c15-`
bpmedia -suspend -m $MEDIA -h $aa
# check suspended
bpmedialist -h $aa -m $MEDIA | grep SUSPENDED > /dev/null
if [ $? -ne 0 ]; then
echo "The media status is not suspended, will continue as not show stopper for moving into onsite pool."
exit
fi
# check status is 0x0
vmquery -m $MEDIA | grep '^status: 0x0' > /dev/null
if [ $? -ne 0 ]; then
echo "The media status is not 0x0, cannot continue"
exit
fi
# get volume pool numbers
aa=`vmquery -m $MEDIA | grep "volume pool" | cut -f 2 -d"(" | sed 's/)//'`
POOL=$aa
# deassign pool to scratch
vmquery -deassignbyid $MEDIA $POOL 0x0
# change pool to onsite
poolVar=`vmpool -listall -bx | grep onsite | awk '{print $2}'`
vmchange -p $poolVar -m $MEDIA
# assign
aa=`bpmedialist -L -m $MEDIA | grep '^allocated' | cut -f 2 -d"(" | sed 's/)//'`
vmquery -assignbyid $MEDIA hcart2 $poolVar 0x0 $aa
#
echo "The media should now be visible in the onsite pool within NetBackup GUI."
echo "The media is suspended meaning no additional backup will ocurr."
echo "The onsite pool is not ejected via vault"
A script is included below the peforms the required functions for moving out of non vault pool.
#!/bin/ksh
# Author: David Spink
#
# Date: Aug 02, 2007
#
# Purpose: Remove media from non eject pool to standard eject pool
#
# How: ./restore_post.sh "mediaid"
#
# check that you are root
id | grep root > /dev/null
if [ $? -ne 0 ]; then
echo "You must be user root to execute $0"
exit
fi
# check parameters are passed
if [ $# -ne 1 ]; then
echo
echo "Usage: $0 mediaID"
echo
echo "Example: $0 713551"
echo
echo
exit
fi
# check media ID is 6 chars or less, note wc counts EOL hence value set to 7
if [ `echo $1 | wc -c` -gt 7 ]; then
echo "Media is longer than 6 chars, please re-enter"
exit
fi
# set variable
MEDIA=$1
# check suspended, we need to ensure the media is still suspend before moving out of onsite pool
aa=`bpmedialist -L -m $MEDIA | grep "Server Host" | cut -c15-`
bpmedialist -h $aa -m $MEDIA | grep SUSPENDED > /dev/null
if [ $? -ne 0 ]; then
echo "The media status is not suspended, cannot continue"
exit
fi
# check status is 0x0
vmquery -m $MEDIA | grep '^status: 0x0' > /dev/null
if [ $? -ne 0 ]; then
echo "The media status is not 0x0, cannot continue"
exit
fi
# get volume pool numbers
aa=`vmquery -m $MEDIA | grep "volume pool" | cut -f 2 -d"(" | sed 's/)//'`
POOL=$aa
# deassign pool to scratch
vmquery -deassignbyid $MEDIA $POOL 0x0
# change pool to one that forms part of vault ejects
poolVar=`vmpool -listall -bx | grep "Windows_OS_Full" | awk '{print $2}'`
vmchange -p $poolVar -m $MEDIA
# assign
aa=`bpmedialist -L -m $MEDIA | grep '^allocated' | cut -f 2 -d"(" | sed 's/)//'`
vmquery -assignbyid $MEDIA hcart2 $poolVar 0x0 $aa
#
echo "The media should now be visible in the Windows OS Full pool within NetBackup GUI."
echo "The media is still suspended meaning no additional backup will ocurr."
echo "The Windows OS Full pool forms part of the Vault process."
echo ""
ACLs DELETERemove ACL entries from files.
#!/bin/sh
#
# delfacl - delete Solaris ACLs
#
case $# in
0)
echo "Usage: delfacl file ..."
exit 1
;;
esac
#
# loop over arguments
#
for file in $*
do
if [ -f $file -o -d $file ]; then
/bin/getfacl $file | /bin/egrep '^(user::|group::|mask:|other:)' | /bin/setfacl -f - $file
else
echo "$file not found"
fi
done
FILE COUNTCount files per directory.
#!/bin/sh
echo "Get list of directories"
find ./ -type d > dirdump.txt
echo "For each directory count list of files non-recursive"
while IFS= read LINE
do
bb=$LINE
aa=`find "$LINE"/* -type d -prune -o -print | wc -l`
cc=`ls -l "$LINE" | awk '{ total += $5 } END { print total }'`
echo $aa $cc $bb >> outputTMP.txt
done < dirdump.txt
cat outputTMP.txt | sort > output.txt
rm outputTMP.txt
echo "Total number of files..." >> output.txt
cat output.txt | awk '{ total += $1 } END { print total }' >> output.txt
CLEAN LOGLog file clean up utility.
#!/bin/sh
# purpose is to clean up logs files
myDate=`/usr/bin/date +%Y-%m-%d`
myVar1=DHTout.txt
myVar2=DHTerr.txt
cd /opt/WebSphere/AppServer/logs
cp $myVar1 old_logs/${myVar1}.${myDate}
cp $myVar2 old_logs/${myVar2}.${myDate}
cat /dev/null > $myVar1
cat /dev/null > $myVar2
cd /opt/WebSphere/AppServer/logs/old_logs
compress ${myVar1}.${myDate} 2> /dev/null
compress ${myVar2}.${myDate} 2> /dev/null
unset $myDate
unset $myVar1
unset $myVar2
RCP FILERemotely copy a file to a list of servers.
#!/bin/sh
HME=/export/home/spi0004
for SERVER in `cat ./servers | grep -v "^#"`
do
echo
echo "Processing server $SERVER"
rcp -p profile ${SERVER}:${HME}/.profile
rcp -p profile_custom ${SERVER}:${HME}/.profile_custom
rcp rhosts ${SERVER}:${HME}/.rhosts
done
Wu-FTP SECUREEnable security for new Wu-FTP user.
#!/bin/ksh
# For cleaning up accounts that use wu-ftp
# Read the username and home directory files into arrays
typeset -i cnt
cnt=1
for SERVER in `cat usernamEhub.txt`
do
my_user[$cnt]=$SERVER
(( cnt = cnt +1 ))
done
cnt=1
for SERVER in `cat userdirEhub.txt`
do
my_dir[$cnt]=$SERVER
(( cnt = cnt +1 ))
done
# Use the contents in the array to cleanup passwd files
typeset -i num
num=cnt
cnt=1
while (( cnt < num ))
do
echo ${my_user[$cnt]} ${my_dir[$cnt]}
cp /etc/passwd ${my_dir[$cnt]}/etc/passwd
cp /etc/group ${my_dir[$cnt]}/etc/group
cat ${my_dir[$cnt]}/etc/passwd | sed -n -e '/^root/p' -e "/^${my_user[$cnt]}/p" > ${my_dir[$cnt]}/etc/newpasswd
mv ${my_dir[$cnt]}/etc/newpasswd ${my_dir[$cnt]}/etc/passwd
cat ${my_dir[$cnt]}/etc/group | sed -n -e '/^root/p' -e '/^ehubftp/p' > ${my_dir[$cnt]}/etc/newgroup
mv ${my_dir[$cnt]}/etc/newgroup ${my_dir[$cnt]}/etc/group
chown -R root:root ${my_dir[$cnt]}/etc ${my_dir[$cnt]}/dev ${my_dir[$cnt]}/usr
chmod 111 ${my_dir[$cnt]}/etc ${my_dir[$cnt]}/dev ${my_dir[$cnt]}/usr
touch ${my_dir[$cnt]}/.rhosts ${my_dir[$cnt]}/.forward
chown root:root ${my_dir[$cnt]}/.rhosts ${my_dir[$cnt]}/.forward
chmod 400 ${my_dir[$cnt]}/.rhosts ${my_dir[$cnt]}/.forward
chmod 444 ${my_dir[$cnt]}/etc/passwd ${my_dir[$cnt]}/etc/group
cat ${my_dir[$cnt]}/etc/passwd
ls -l ${my_dir[$cnt]}/.forward ${my_dir[$cnt]}/.rhosts
echo ""
(( cnt = cnt + 1 ))
sleep 1
done
NDD INFOSee NDD info.
#!/bin/ksh
#
# ndd.sh
#
PATH=/usr/sbin:$PATH
if [ -z "$1" ]; then
echo "Usage: $0 [udp | tcp | ip | icmp | arp | ... ]"
exit
fi
ndd /dev/$1 '?' | nawk -v c="ndd /dev/$1" '
/write/ {
split($0,a,/[ \t(]/);
n=c t " " a[1];
printf "echo %s = ",a[1];
printf "`%s`\n",n;
}' | sh
RSYNCUse Rsync for DR.
#!/usr/bin/ksh
#
# Script: ehubdr_sync_call.sh
#
# Date: 07 Jul, 2005
#
# Called: from root cron
#
# Purpose: Sync directories from d2pr0007 to d1ua0003 for Ehub DR
#
# Set environment
cd /app/drsync
myDate=`/usr/bin/date +%Y-%m-%d`
LOG=output.${myDate}.log
ERRORLOG=error.${myDate}.log
# Move old logs files
mv output.*.log ./logs > /dev/null 2>&1
mv error.*.log ./logs > /dev/null 2>&1
# Set logging
exec >> $LOG 2> $ERRORLOG
# Rsync /app/cpships
echo "Sync d2pr0007:/app/cpships to d1ua0003:/app/cpships"
/usr/local/bin/rsync -avz --rsync-path=/usr/local/bin/rsync --exclude backup/ --progress /app/cpships d1ua0003:/app/ehubdr
# Rsync /app/mercator
echo "Sync d2pr0007:/app/mercator tp d1ua0003:/app/mercator"
/usr/local/bin/rsync -avz --rsync-path=/usr/local/bin/rsync --progress /app/mercator d1ua0003:/app/ehubdr
VXDG ADD DISKSPlace disks into Veritas disk group.
# Before running create disk group
# Example of disks contained in diskfile.txt - c1t0d43
# Example of output - sapdg01=c1t0d43
typeset -i cnt
cnt=0
for i in `cat diskfile.txt`
do
# configure disk for VxVM use
/usr/lib/vxvm/bin/vxdisksetup -i $i format=sliced
#set name
if [ $cnt -lt 10 ];then
xx=sapdg0${cnt}
else
xx=sapdg${cnt}
fi
(( cnt = cnt +1 ))
# add disk to a disk group
vxdg -g d1ua0002-sapdg adddisk $xx=$i
echo $xx=$i
done
KSH SYNTAXArithmetric. (( x = 24 + 25 )) ;result 49 (( x = 100 - 25 )) ;result 75 (( x = 4 * 5 )) ;result 20 (( x = 10 / 3 )) ;result 3 (( x = 10 % 3 )) ;result 1 Numeric. (( num1 == num2 )) (( num1 != num2 )) (( num1 < num2 )) (( num1 > num2 )) (( num1 <= num2 )) (( num1 >= num2 )) Strings. [[ str1 == str2 ]] [[ str1 != str2 ]] [[ str1 == pattern ]] [[ str1 != pattern ]] [[ str1 < str2 ]] [[ str1 > str2 ]] [[ -z str1 ]] ;str1 has length zero [[ -n str1 ]] ;str1 has nonsero length (contains one or more chars) Variables.
mv $filename $filenameX ;shell thinks these are both legal variables
mv $filename ${filename}X ;delimit end of variable name by enclosing in { }
rcp -p profile ${SERVER}:${HME}/.profile ;example
rcp -p profile_custom ${SERVER}:${HME}/.profile_custom
Using Arrays.
ARRAY
typeset -i cnt
cnt=1
for SERVER in `cat usernamEhub.txt`
do
my_user[$cnt]=$SERVER
(( cnt = cnt +1 ))
done
Command Line Parameters.
$0 ;script name
$1 ;value of first argument
$2 ;value of second argument
${10},{11} ;value of tenth argument
$# ;number of arguments passed to the script
$* ;value of all command-line arguments
File Owner. [ -r file ] ;can file be read by user [ -w file ] ;can file be altered by user [ -x file ] ;can file be executed by user [ -O file ] ;is the file owned by effective user ID of this process [ -G file ] ;if the file group the effective group ID of this process [ -u file ] ;does file have suid set [ -g file ] ;does file have guid set [ -k file ] ;does file have sticky bit set [ -f file ] ;regular file? [ -d file ] ;directory? [ -c file ] ;char file? [ -b file ] ;block special file? [ -p file ] ;is the file a named pipe? [ -S file ] ;is the file a socket? [ -L file ] ;is the file a symlink? [ -s file ] ;does file exist and have size greater than 0 [ -e file ] ;does the file exist IF statement examples. if [ $? -eq 0 ]; then ;condition true if [ $? -ne 0 ]; then ;condition false if [ $# != 4 ]; then ;not equal if [ $2 -ne 3003 ]; then ;not equal if [ 5 != 2 -a 3 != 4 ] ;not equal if [ $dummy != "y" -o $dummy != "Y" ];then ;if either first or second expression is true if [ $LOGNAME = "doracle" ] || [ $NODE = "dd2pr0008" ] ;if either first or second expression is true if [ $3 -lt 1000 ]; then ;less than if [ $1 -le 3000 ]; then ;less than equal if [ $3 -gt 9 ]; then ;greater than if [ -f createq$4.scp ]; then ;file exists Regular Expressions.
/ ... / ;look for three chars surrounded by
/^the/ ;find the line that starts with the
s/^/>>/ ;insert at beginning of the line
contents$ ;matches only if at end of the line
[tT]he ;find the or The
$s/[aeiouAEIOU]//g ;delete all vowel words
/[0-9]/ ;find a line containing a digit
/^[A-Z]/ ;find a line starting with an upper case letter
X* ;in regular expression this means zero or more occurrences of preceding char
XX* ;same as X* in that matches zero or more occurrences of preceding char
s/ */ /g ;change multiple blanks to single blanks
.* ;zero or more occurences of any chars
X\{1,10\} ;matches from 1 to 10 occurences of X
[A-Za-z]\{4,7\} ;matches sequence of alphabetic letters four to seven chars long
[A-Za-z]\{7\} ;matches sequence of alphabetic letters seven chars long
s/^.\{10\}// ;delete the first 10 chars from the line
s/^.\{10\}$// ;delete the last 10 chars from the line
s/[a-zA-Z]\{6,\}/X/g ;change words at least 6 letters long to X
s/\(.*\) \(.*\)/\2 \1/ ;switch the two fields
Shell MetaChars.
|