1833187 Members
2816 Online
110051 Solutions
New Discussion

Configuration files

 
Rajkumar_3
Regular Advisor

Configuration files

Hai All,

I have to develop the script like this...

suppose i declared an Environment variable in HP-Unix like
# test=database.props
(database.props is the property file)

In that "database.props" file i have the content like this.

# vi database.props

FILE_NAME=cdr (cdr is the extension of the file)
RETAIN_PEND=10 (assumption is 10 days)

BACK_FILE_EXT=_x ( _x is the extension ends with the filename)
RETAIN_SEND=3 (Assumption is 3 days)

DB_=
DB_=
DB_=
DB_=
DB_=
DB_=
DB_=
etc...........
---------------------------------------------------------------------------
Note1:
------
The file name which ends with "cdr" should be read from the 'FILE_NAME' and it should be deleted based on the "RETAIN_PEND" value..

Note2:
-------
The file name which ends with "_x" should be read from the 'BACK_FILE_EXT' and it should be deleted based on the "RETAIN_PEND" value..

Note3:
--------
To delete the file we should search for the files which is available from the "DB_" parameter.Because there will be so many product_id's starting with "DB_=/".So we should read the directory paths from the "DB_" parameter to delete a file based on the paramters above..

Note4:
--------
The Error status of the files should be written to "syslog" using "Logger" Command in the

Is it possible to delete the file like this..Can any one can help me

Note5:
--------
I have attached sample script which delete the files for every 3 days(hardcoded) based on the directory specified in the Environment variable..
This script i recieved from the FAQ

Thanks for the advance in help...

Thanks & regards
Rajkuma
Oracle DBA
18 REPLIES 18
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai All,

Can anyone can provide a script for the above requirement..Its urjent please

Thanks
Rajkumar
Oracle DBA
Robin Wakefield
Honored Contributor

Re: Configuration files

Hi Rajkumar,

System's a bit slow today, but try the following:

==========================================
#!/bin/ksh

. ~/database.props

set | grep DB_ | cut -d= -f2 | while read DIR ; do

if [ ! -d "$DIR" ] ; then
logger "$0 : $DIR not found"
fi

COUNT=0

find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | while read FILE ;
rm $FILE && logger "$0 : for directory $DIR, $FILE deleted"
COUNT=$(expr $COUNT + 1)
done

find $DIR -name "*${BACK_FILE_EXT}" -mtime +${RETAIN_SEND} | while read FILE ;
rm $FILE && logger "$0 : for directory $DIR, $FILE deleted"
COUNT=$(expr $COUNT + 1)
done

if [ "$COUNT" -gt 0 ] ; then
logger "$0 : for directory $DIR, $COUNT files removed"
else
logger "$0 : for directory $DIR, no matching files found"
fi

done
exit 0
=========================================

Rgds, Robin
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Robin,

Thank you very much for your reply robin.Yes system is very slow today..

I have some queries in the program...

1)
You have mentioned . ~/database.props in the beginning of the file..That means are you reading it from the environment Variable 'TEST' ? Because that "database.props" is not a constant file..User may change it tomorrow..So we have to read it from the environment variable...Is it possible to do it in that way..?? That property file should not be hardcoded...

2)

set | grep DB_ | cut -d= -f2 | while read DIR ; do

In HP_Unix can we use "SET" while declaring the enviroment variable??? Because in sunSolaris we can declare like that..but In HP is it possible...???


Thanks & Regards
Rajkuma
Oracle DBA
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Robin,

I forgot to tell you that database.props file will be available in the another environment variable..


GW_GEN_CONFIG_DIR
=/gateway/config

TEST=DATABASE.PROPS

Waiting for your reply..

Thanks & regards
Rajkumar
Oracle DBA
Robin Wakefield
Honored Contributor

Re: Configuration files

Hi Rajkumar,

If you want to run this through cron, you'll need to specify this external file somewhere other than in an environment variable so that the script can source it. Is the GW_GEN_CONFIG_DIR fixed - can it be hardcoded in the script, and therefore used to find the location of the db_props file?

The set command you are probably talking about is the csh command that is used to set variables. The set I have used in the script is to output the current list of variables so that I can search for those starting "DB_".

System is getting slower by the hour, don't know if it's me or not.

Rgds, Robi
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Robin,

Thank you for your reply..

A)
GW_PIMEIUP_PROPERTY_FILE= :
This is nothing but a propertyfile.This name is not static.Tomorrow it may change.so we have to read this "GW_PIMEIUP_PROPERTY_FILE=" to get the property file name..
For eg:
GW_PIMEIUP_PROPERTY_FILE - Environment variable...
- is the property file name.This file name should not be hardcoded in the script.

B)
GW_GEN_CONFIG_DIR=
:
This is the environment variable where all the property files are stored.This is static.This directory name is fixed.
for eg:
GW_GEN_CONFIG_DIR - Environment variable...
- This is the directory path for property file name.This directory is fixed.

In " DB_ " the directory path is available to delete the files as discussed above..

Waiting for your response..

Thanking you..

Regards
Rajkuma
Oracle DBA
Robin Wakefield
Honored Contributor

Re: Configuration files

Hi Rajkumar,

The problem is that you want to run this through cron. You cannot set an environment variable in your shell, and expect cron to know about it. That is why I think you will have to use a file containing the location of your data.

What causes the property file to change? Can this change not automatically update the config file?

Rgds, Robin
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Robin,

Its working fine..Thanks you..

In the property file "database.props" we are taking
these parameters..
FILE_NAME=CDR
BACK_FILE_EXT=_x
RETAIN_SEND=3
RETAIN_PEND=5
BAC_FILE001=
BAC_FILE002=

This way its working fine..

Till now we are deleting the files ending with "_x" along with CDR extention.Is it possible to delete the files starting with " x_" along with CDR ??

--"BACK_FILE_EXT=_x"

BACK_FILE_EXT=x_ ?????

Waiting for your reply...

Regards
Rajkuma
Oracle DBA
Eugen Cocalea
Respected Contributor

Re: Configuration files

Hi,

Why not define any path/variable/whatever that it may change in the future at the beginning of the script? When you will change the name of the path/variable/whatever, you will surely remember to modify in only one more place, in the script. It's not that hard. Using environment variables is not working very well whilst using cron.

E.
To Live Is To Learn
Eugen Cocalea
Respected Contributor

Re: Configuration files

Hi Raj,

define in database.props another variable, let's say BACK_FILE_PRE=x_

replace the line from Robins' script

find $DIR -name "*${BACK_FILE_EXT}" -mtime +${RETAIN_SEND} | while read FILE ;

with

find $DIR -name "${BACK_FILE_PRE}*" -mtime +${RETAIN_SEND} | while read FILE ;

should work.

E.
To Live Is To Learn
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai ,

Yes you are correct..I will work in that way..The problem is suppose..
BAC_FILE001=/test1
BAC_FILE002=/test2

In this directories i created a files as per my Requirement..When i execute it its working fine..if i wont create any files in the test2 directory..The files are not deleting even though the files are in test1....If the files is in two directories its working..
What could be the reason???

Thanks
rajkumar
Oracle DBA
Eugen Cocalea
Respected Contributor

Re: Configuration files

Hi,

Well, you changed your mind again.

DB_name or BAC_name? Please decide. If you want to use BAC, replace

set | grep DB_ | cut -d= -f2 | while read DIR ; do

with

set | grep BAC_ | cut -d= -f2 | while read DIR ; do

E.
To Live Is To Learn
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Eugen,

I was mistakenly used BAC_ instead of DB_

Can you please tell me the above previous reason???

Thanking you

Regards
Raj
Oracle DBA
Eugen Cocalea
Respected Contributor

Re: Configuration files

Hi,

The reason might be that the files are not 3 days old. For testing purposes, you either remove the +mtime condition on the find statement or you use touch to change the timestamps on the files.

E.
To Live Is To Learn
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai Eugen,

I have created the same files in the /test1 /test2 directories using the touch command...Still it was like that only..

What could be the reason??
Thanks
Raj
Oracle DBA
Robin Wakefield
Honored Contributor

Re: Configuration files

Hi Rajkumar,

Can you shows us the current script/config files that you're testing against. Also can you do an "ls -l" of the files in your test area?

Thanks, Robin
Eugen Cocalea
Respected Contributor

Re: Configuration files

Hi Raj,

(man touch)

touch 10150000 //

that will change the date on the file to 15th of Oct and the time to 00:00.

then try the script. should work.

E.
To Live Is To Learn
Rajkumar_3
Regular Advisor

Re: Configuration files

Hai robin,E

Great.Its working fine..

Thanks...

Regards
Raj
Oracle DBA