1825789 Members
2126 Online
109687 Solutions
New Discussion

Help in script

 
SOLVED
Go to solution
Waqar Razi
Regular Advisor

Help in script

I am writing a script for DR, the script does vgexport, put the date stamp at the end of the file and then put map files and outfiles of each volume group in the /dr_hostname/lvm_info directory. What I want is to keep the last 5 copies of each map and outfile of each volume group and delete any thing prior to the last 5 copies. Can some one help me in this?
4 REPLIES 4
Waqar Razi
Regular Advisor

Re: Help in script

I have attached a copy of the script as well and here it is again:

vgdate=$(date +'%d%m%y')
# echo $vgdate
DR_dir=/DR_$(hostname)/lvm_info/
mkdir $DR_dir
# echo $DR_dir
for i in /dev/vg*/group
do
# ll $i
vgname=$(echo $i | cut -d "/" -f 1,2,3)
# echo $vgname
vgdisk=$DR_dir$(echo $vgname | cut -d "/" -f 3).disks.$vgdate
# echo $vgdisk
rm $vgdisk
vgmap=$DR_dir$(echo $vgname | cut -d "/" -f 3).map.$vgdate
# echo $vgmap
rm $vgmap
vgexpcmd="vgexport -m $vgmap -p -s -v -f $vgdisk $vgname"
$vgexpcmd
done
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help in script

Hi Wagar:

# cd ${DR_dir} && rm $(ls -t map.*|tail +6) 2>/dev/null

Regards!

...JRF...

Waqar Razi
Regular Advisor

Re: Help in script

Can you please modify the script?
James R. Ferguson
Acclaimed Contributor

Re: Help in script

Hi (again):

My suggestion goes at your script's end:

cd ${DR_dir} || exit 1
rm $(ls -t *.map.*|tail +6) 2>/dev/null
rm $(ls -t *.disks.*|tail +6) 2>/dev/null

...and assumes the nomenclature you have used.

Regards!

...JRF...