script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6) (371 Views)
Reply
Occasional Contributor
srinivasvankina
Posts: 6
Registered: ‎05-23-2014
Message 1 of 11 (371 Views)
Accepted Solution

script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

Hi every one,

 

I new scripting in HP unix operating system.

 

I require a script, which do the following given below example.

 

When '/oracle/<SID>/oraarch' filesystem usage is 80%.  It has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata6'. 

 

And

if '/oracle/<SID>/sapdata6' filesystem usage is 90%. It has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata7'

 

And

if '/oracle/<SID>/sapdata7' filesystem usage is 90%. It has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata8'

 

And 

if '/oracle/<SID>/sapdata8' filesystem usage is 90%. It has to delete '*.dbf' files from '/oracle/<SID>/sapdata6' and it has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata6'

 

And 

if '/oracle/<SID>/sapdata6' filesystem usage is 90%. It has to delete '*.dbf' files from '/oracle/<SID>/sapdata7' and it  has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata7'

 

And 

if '/oracle/<SID>/sapdata7' filesystem usage is 90%. It has to delete '*.dbf' files from '/oracle/<SID>/sapdata8' and it has to move '*.dbf' files from '/oracle/<SID>/oraarch' to '/oracle/<SID>/sapdata8'.

 

Please help me for this script. It is very important for daily routine task.

 

Thanks in Advance.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,877
Registered: ‎03-06-2006
Message 2 of 11 (335 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

[ Edited ]

You need to break your requirements into smaller tasks that can be done by separate functions or scripts.


1) You seem to need a function to return usage of a filesystem.

2) A function to move files

3) A function to delete files.

 

You then call the above functions passing the various sources and targets:

SID=XXX

FS=/oracle/$SID/oraarch

src=$FS

TGT=/oracle/$SID/sapdata6

usage_limit=80

usage=$(get_fs_usage $FS)

if [ $usage -ge $usage_limit ]; then

   move_files $src $TGT

fi

 

FS=/oracle/$SID/sapdata6

TGT=/oracle/$SID/sapdata7

usage_limit=90

usage=$(get_fs_usage $SRC)

if [ $usage -ge $usage_limit ]; then

   move_files $src $TGT

fi

 

FS=/oracle/$SID/sapdata7

TGT=/oracle/$SID/sapdata8

usage=$(get_fs_usage $SRC)

if [ $usage -ge $usage_limit ]; then

   move_files $src $TGT

fi

 

FS=/oracle/$SID/sapdata8

TGT=/oracle/$SID/sapdata6

usage=$(get_fs_usage $SRC)

if [ $usage -ge $usage_limit ]; then

   remove_files $TGT

   move_files $src $TGT

fi

...

 

You could combine the steps that have to delete with the ones that don't by passing a parm to indicate that step.  And then you can use the same function to do all 6 steps.

Please use plain text.
Occasional Contributor
srinivasvankina
Posts: 6
Registered: ‎05-23-2014
Message 3 of 11 (317 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

To get percentage value of filesystem. I written the script given below. 

 

SID=XXX
FS=/oracle/$SID/oraarch
src=$FS
TGT=/oracle/$SID/sapdata6
usage_limit=80
usage=$(bdf | egrep "/oracle/RRP/oraarch" | awk '{print $5}')

echo "$usage"
if [ $usage -ge $usage_limit ]; then
       mv $SRC $TGT
fi

 

After executing the script, I got the following error.

 

# ./scriptoraarch.sh
28%
./scriptoraarch.sh[8]: 28%: Expression is not complete; more tokens expected.
You have mail in /var/mail/root
#

 

I need to remove the percentage(%) symbol from the number (ex.28%). which comes output of following line usage=$(bdf | egrep "/oracle/XXX/oraarch" | awk '{print $5}').

 

Please help me.

Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,078
Registered: ‎02-23-2005
Message 4 of 11 (311 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,877
Registered: ‎03-06-2006
Message 5 of 11 (303 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

[ Edited ]

>I need to remove the percentage(%) symbol from the number

 

You can simply do it with awk, also no need to use the egrep hammer:

usage=$(bdf $FS | awk '{print substr($5, 1, length($5)-1}')

 

Note: If your filesystem string is too long to fit, bdf(1) will display on two lines.

Please use plain text.
Occasional Contributor
srinivasvankina
Posts: 6
Registered: ‎05-23-2014
Message 6 of 11 (255 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

Hi

 

I had done my self. I done the script in another way. Script given below.

 

#Initiliaze Values in varaiables
SID=XXX
FS=/oracle/$SID/oraarch
src=$FS
TGT_SD6=/oracle/$SID/sapdata6
TGT_SD7=/oracle/$SID/sapdata7
TGT_SD8=/oracle/$SID/sapdata8

#Calculating the usage limit of the filesystem /oracle/$SID/oraarch by 70 percentage
ora_lt=$(bdf | egrep "/oracle/$SID/oraarch" | awk '{print $2}')
ora_lt_div=$((ora_lt/100))
ora_lt_p=$((ora_lt_div*70))
#echo "$ora_lt_p"

#Calculating the usage of the filesystem /oracle/$SID/oraarch
ora_gw=$(bdf | egrep "/oracle/$SID/oraarch" | awk '{print $3}')

#Calculating the usage limit of the filesystem /oracle/$SID/sapdata6 by 60 percentage
SD6_lt=$(bdf | egrep "/oracle/$SID/sapdata6" | awk '{print $2}')
SD6_lt_div=$((SD6_lt/100))
SD6_lt_p=$((SD6_lt_div*60))
#echo "$SD6_lt_p"

#Calculating the usage of the filesystem /oracle/$SID/sapdata6
SD6_gw=$(bdf | egrep "/oracle/$SID/sapdata6" | awk '{print $3}')

#Calculating the usage limit of the filesystem /oracle/$SID/sapdata7 by 50 percentage
SD7_lt=$(bdf | egrep "/oracle/$SID/sapdata7" | awk '{print $2}')
SD7_lt_div=$((SD7_lt/100))
SD7_lt_p=$((SD7_lt_div*50))
#echo "$SD7_lt_p"

#Calculating the usage of the filesystem /oracle/$SID/sapdata7
SD7_gw=$(bdf | egrep "/oracle/$SID/sapdata7" | awk '{print $3}')

#Calculating the usage limit of the filesystem /oracle/$SID/sapdata8 by 40 percentage
SD8_lt=$(bdf | egrep "/oracle/$SID/sapdata8" | awk '{print $2}')
SD8_lt_div=$((SD8_lt/100))
SD8_lt_p=$((SD8_lt_div*40))
#echo "$SD8_lt_p"

#Calculating the usage of the filesystem /oracle/$SID/sapdata8
SD8_gw=$(bdf | egrep "/oracle/$SID/sapdata8" | awk '{print $3}')

#Checking usage growth with usage limit and moves *.dbf files to sapdata6, sapdata7 & sapdata8 file systems
if [ $ora_gw -ge $ora_lt_p ] && [ $SD6_gw -le $SD6_lt_p ]
then
find $SRC -type f -name RRParch1*.dbf -mtime +1 -exec mv -f {} $TGT_SD6 \;
elif [ $ora_gw -ge $ora_lt_p ] && [ $SD6_gw -ge $SD6_lt_p ] && [ $SD7_gw -le $SD7_lt_p ]
then
find $TGT_SD6 -type f -name RRParch1*.dbf -exec mv -f {} $TGT_SD7 \;
find $SRC -type f -name RRParch1*.dbf -mtime +1 -exec mv -f {} $TGT_SD6 \;
elif [ $ora_gw -ge $ora_lt_p ] && [ $SD6_gw -ge $SD6_lt_p ] && [ $SD7_gw -ge $SD7_lt_p ] && [ $SD8_gw -le $SD8_lt_p ]
then
find $TGT_SD7 -type f -name RRParch1*.dbf -exec mv -f {} $TGT_SD8 \;
find $TGT_SD6 -type f -name RRParch1*.dbf -exec mv -f {} $TGT_SD7 \;
find $SRC -type f -name RRParch1*.dbf -mtime +1 -exec mv -f {} $TGT_SD6 \;
elif [ $ora_gw -ge $ora_lt_p ] && [ $SD6_gw -ge $SD6_lt_p ] && [ $SD7_gw -ge $SD7_lt_p ] && [ $SD8_gw -ge $SD8_lt_p ]
then
find $TGT_SD8 -type f -name RRParch1*.dbf -exec rm -f {} \;
find $TGT_SD7 -type f -name RRParch1*.dbf -exec mv -f {} $TGT_SD8 \;
find $TGT_SD6 -type f -name RRParch1*.dbf -exec mv -f {} $TGT_SD7 \;
find $SRC -type f -name RRParch1*.dbf -mtime +1 -exec mv -f {} $TGT_SD6 \;
fi

Please use plain text.
Honored Contributor
Bill Hassell
Posts: 14,200
Registered: ‎05-29-2000
Message 7 of 11 (249 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

[ Edited ]

bdf can be very slow on big systems, especially if there are NFS mounts.

Here is a way to write scripts to only call bdf once, only for local filesystems, and handle split lines:

 

export BDF=$(bdf -l | while read FS TOT USED AVAIL PERCENT MNT
  do
    if [[ $FS != "Filesystem" ]]
    then
       if [[ "$TOT" = "" ]]
       then
         read TOT USED AVAIL PERCENT MNT
       fi
       echo "$(echo $FS $TOT $USED $AVAIL $PERCENT $MNT | tr -d '%')"
    fi
  done)

 Now in the rest of the script, you replace the bdf command with $(echo "$BDF") as in:

 

$(echo "$BDF") | grep $FS

 

(note: $BDF has the % character removed to make parsing the percentage value easier)

Since the bdf text is all in memory, the results are very fast and don't require any help from HP-UX.

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,877
Registered: ‎03-06-2006
Message 8 of 11 (235 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

You can make several optimizations:

   ((ora_lt_div = ora_lt / 100))

 

And no need to compute ora_lt_div:

((ora_lt_p = ora_lt / 100 * 70))

>ora_lt=$(bdf | egrep "/oracle/$SID/oraarch" | awk '{print $2}')

 

There is no need to use egrep and if /oracle is a filesystem, you can simply to:

ora_lt=$(bdf  "/oracle/$SID/oraarch" | awk '{print $2}')

 

And awk can do the percentage calc too:

ora_lt=$(bdf  "/oracle/$SID/oraarch" | awk 'BEGIN {OFMT="%.0f"} {print $2 * .70 }')

 

And of course, there is no reason awk can't compute the limit and usage in the same line.  You would need to assign to an array.

 

find $TGT_SD8 -type f -name RRParch1*.dbf -exec rm -f {} +  # Using "+" is much faster

 

For numeric variables you can use C style expressions:

if (( ora_gw >= ora_lt_p && SD6_gw <= SD6_lt_p )); then

Please use plain text.
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 9 of 11 (191 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

Hello,

 

 Now in the rest of the script, you replace the bdf command with $(echo "$BDF") as in:

$(echo "$BDF") | grep $FS

 

i get an error , when i use this it ?

 

do you mean?

echo "$BDF"  | grep $FS

 

it test it with "echo "$BDF"  | grep/tmp"

 

regards

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,877
Registered: ‎03-06-2006
Message 10 of 11 (180 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

>do you mean? echo "$BDF" | grep $FS

 

Yes, that makes more sense.

Please use plain text.
Honored Contributor
Bill Hassell
Posts: 14,200
Registered: ‎05-29-2000
Message 11 of 11 (170 Views)

Re: script required to move files from (/oracle/SID/oraarch) to (/oracle/SID/sapdata6)

[ Edited ]

You and Dennis are correct. Just echo the BDF variable using quotes and grep for the mountpoint:

 

"echo "$BDF"  | grep /tmp

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation