script to read configuration file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to read configuration file
# 1  
Old 04-05-2004
Question script to read configuration file

Hi,

I would like to write a Korn shell script which will remove files older than a certain date. In my script, it will read a configuration file with the following entries:

# <directory> <filename wildcard>
#
/home/philip/log *.log
/home/philip/log1 delete-me*.log


The cleanup script will then process the configuration file line by line and read the directory path (DIRPATH) and filetype (FILETYPE).

Then i will have a find statement

find $DIRPATH -name $FILETYPE -mtime +7 -exec /bin/rm \{} \;


Below is the code segment:



cat $CONFIG | while read LINE
do
case $LINE in
\#*) ;;
'') ;;
*)
mydir="`echo $LINE | awk '{ print $1 }'"
filetype="`echo $LINE | awk '{ print $2 }'"
if [ -z $mydir ] || [ -z $filetype ]; then
echo "empty values for directory or file type"
exit 1
fi
find $mydir -name $filetype -mtime +${PURGE_DAYS} -exec /bin/rm \{} \;

;;
esac




When i run the script, at the time when it read the configuration file, it expanded the filetype variable to (1.log 2.log 3.log etc). when the program got to the find command , it just failed.

How do i make it to store *.log in the filetype variable so that i could pass it to find command?

Thanks in advance

philip
# 2  
Old 04-05-2004
Let ksh do more of the work. Try:

exec < $CONFIG

while read mydir filetype ; do
case $mydir in

etc
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to Read the given file contents into a merged one file

Like to have shell script to Read the given file contents into a merged one file with header of path+file name followed by file contents into a single output file. While reading and merging the file contents into a single file, Like to keep the format of the source file. ... (4 Replies)
Discussion started by: Siva SQL
4 Replies

2. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

3. Shell Programming and Scripting

Read Oracle connection details from a configuration file

Hi, Is it possible to pass oracle connection information from a configuration file and use that to connect to oracle database in my unix shell scripts. Following is the scenario: (1) I would like to save oracle connection string details in a configuration file (ex., dbconfig.txt) (2) from my... (6 Replies)
Discussion started by: sudhakaratp
6 Replies

4. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

5. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

6. Shell Programming and Scripting

Script to increase Timeout values in Configuration File

Hi Guys I am using one configuration file for reading some time out values.The format of the file is A.Type = Number A.Val = 2000 B.Type = Number B.Val = 4000 Now my requirement is I need to write a shell script in Solaris where i need to increase these timeout values by 10 times of... (3 Replies)
Discussion started by: mr_deb
3 Replies

7. UNIX for Dummies Questions & Answers

Issue with use of Configuration file instead of hardcoded values inside the script

Hi, My code works perfectly fine. But, $my $min_to_add = 1 * 1 * 60; and my $hr_to_sub = 1 * 1 * 86400; i may need to change the values in future. so am keeping them in a separate configuration file like MIN = 1 * 1 * 60 HR = 24 * 60 * 60 in the script, i use a package use et_config... (3 Replies)
Discussion started by: irudayaraj
3 Replies

8. Shell Programming and Scripting

Need shell script to read two file at same time and print out in single file

Need shell script to read two file at same time and print output in single file Example I have two files 1) file1.txt 2) file2.txt File1.txt contains Aaa Bbb Ccc Ddd Eee Fff File2.txt contains Zzz Yyy Xxx (10 Replies)
Discussion started by: sreedhargouda
10 Replies

9. Shell Programming and Scripting

Shell script that reads from configuration file to get database

Hi intelligent beings, I am trying to write a script that 1. Accepts the following arguments: store_number div_number user_id div_code 2. Will read from a configuration file to get the Database 3. Use the div_code to determine which value to retrieve from the configuration file ... (1 Reply)
Discussion started by: dolo21taf
1 Replies

10. Shell Programming and Scripting

How to read the configuration file from shell script

Hello all, Please let me know if anyone have the idea how to read the configuration file from the shell script? Thanks in advance, Nishanth (7 Replies)
Discussion started by: nishanth hampal
7 Replies
Login or Register to Ask a Question