Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Go to solution
srinivasvankina
Occasional Contributor

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.

10 REPLIES
Dennis Handly
Acclaimed Contributor

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

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.

srinivasvankina
Occasional Contributor

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.

Steven Schweda
Honored Contributor

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

 
Dennis Handly
Acclaimed Contributor

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

>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.

srinivasvankina
Occasional Contributor
Solution

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

Bill Hassell
Honored Contributor

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

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.

 



Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

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

support_billa
Valued Contributor

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

Dennis Handly
Acclaimed Contributor

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.

Bill Hassell
Honored Contributor

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

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

 

"echo "$BDF"  | grep /tmp



Bill Hassell, sysadmin