Sponsored Content
Top Forums Shell Programming and Scripting Not to remove Files based on property value Post 303002615 by sukhdip on Tuesday 29th of August 2017 07:25:16 AM
Old 08-29-2017
Not to remove Files based on property value

Hi All,

Need your help to fix one script.

Main agenda is:
1. Read a property file.
2. Delete all files in directory except the name from Property file.

I am trying to read property file for value then deleting all files from directory except THAT value/name.

I have tried so far as below:
Property File i.e., earBuild.properties
Code:
#EAR Names
earName=XYZ.ear

OR
Property file can be with Multiple Ear names as:
Code:
#EAR Names
earName=XYZ.ear
earName=ABC.ear


I have written below shell script but loop is deleting all files in directory.

Code:
#!/bin/bash

echo "Reading property file at `pwd`"
ls -lrt

find /tmp/s/earProps/ -name earBuild.properties

FILE_NAME="earBuild.properties"
echo "EAR property file is: $FILE_NAME"

EARPATH="/tmp/s/props/ears/"

# Key in Property File
KEY="earName"

# Variable to hold the Property Value
prop_value=""

getProperty()
{
        prop_key=$1
        prop_value=`cat ${FILE_NAME} | grep ${prop_key} | cut -d'=' -f2`
}

getProperty ${KEY}
echo "KEY = ${KEY} ; Value = " ${prop_value}

for i in ${prop_value}; do
	find $EARPATH -type f ! -name $i -exec rm -rf {} \;
	echo "Value of I in loop is $i"
done


I am no bound to use find or rm or even for loop. Looking for the solution.
Appreciate help in advance.

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove files based on date

I am trying to write a shell script that will remove files in a directory based on the date. For instance, remove all files older than yesterday. Any ideas? (4 Replies)
Discussion started by: hshapiro
4 Replies

2. UNIX for Dummies Questions & Answers

Design Options for Property Files

Dear all, Hello and Good Morning. I have a properties file in a specific directory in UNIX that can be accessed by certain users. This properties file is being used by a number of backend programs. The properties file contain the username and the password of the database as well. How do I design... (1 Reply)
Discussion started by: jackal28
1 Replies

3. Shell Programming and Scripting

Remove/Find files based on position pattern

Hi All, Please help me to find or remove files based on position based search pattern. file1.txt: aaabbbccc dddeeefff iiijjjkkk file2.txt: lllmmmnnn ooopppqqq rrrsssttt file3.txt: uuuvvvwww xxxeeeyyy zzzcccooo From the above files, I like to delete the files that have "eee"... (1 Reply)
Discussion started by: kumarn
1 Replies

4. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

5. Shell Programming and Scripting

Remove duplicate files based on text string?

Hi I have been struggling with a script for removing duplicate messages from a shared mailbox. I would like to search for duplicate messages based on the “Message-ID” string within the messages files. I have managed to find the duplicate “Message-ID” strings and (if I would like) delete... (1 Reply)
Discussion started by: spangberg
1 Replies

6. UNIX for Dummies Questions & Answers

Remove files based on date

Hello team, I have a number of files in a folder which are dated yesterday and today.Can i remove all the files which i created today based on date?? is there any syntax for this ?? (1 Reply)
Discussion started by: kanakaraju
1 Replies

7. Shell Programming and Scripting

Report a missing property and property value mis match script.

Hi All, I have 2 properties files - one is a master templete and other one is a node specific properties file, I need to comapre these 2 properties files and make sure the node Specific properties file contains all the properties in the master temple properties file else report the missing... (5 Replies)
Discussion started by: jayka
5 Replies

8. Shell Programming and Scripting

remove column based on the same value

Hello, I have some problem to remove the columns which have the duplicate value of -9 which is in every row except -9 in some row. Input file showed in below : Col1 Col2 Col3 Col4 Col5 Col6 A 1 A -9 0 -9 B 2 T -9 -9 -9 C 3 D -9 1 -9 D 4 R -9 2 -9 Output should... (6 Replies)
Discussion started by: awil
6 Replies

9. Shell Programming and Scripting

Two files, remove lines from second based on lines in first

I have two files, a keepout.txt and a database.csv. They're unsorted, but could be sorted. keepout: user1 buser3 anuser19 notheruser27 database: user1,2343,"information about",field,blah,34 user2,4231,"mo info",etc,stuff,43 notheruser27,4344,"hiya",thing,more thing,423... (4 Replies)
Discussion started by: esoffron
4 Replies

10. Solaris

Find highest value of a particular property in multiple files

I have multiple files with pattern of "*.tps (example:tps-20170307170421560-1053.tps)" in my log directory(files are in different sub directories). entries in files are given below. I want to extract highest value of endtime accross all files. "endTime :1488902691462" ... (7 Replies)
Discussion started by: Agoyals1986
7 Replies
svcprop(1)																svcprop(1)

NAME
svcprop - retrieve service configuration properties SYNOPSIS
svcprop [-fqtv] [-C | -c | -s snapshot] [-p [name/]name]... [FMRI | pattern]... svcprop -w [-fqtv] [-p [name/]name] {FMRI | pattern} The svcprop utility prints values of properties in the service configuration repository. Properties are selected by -p options and FMRI op- erands. By default, when a single property is selected, its values are printed separated by spaces on a single line. Empty ASCII string values are represented by a pair of double quotes (""). Bourne shell metacharacters (';', '&', '(', ')', '|', '^', '<', '>', newline, space, tab, backslash, '"', single-quote, '`') in ASCII string values are quoted by backslashes (). When multiple properties are selected, a single line is printed for each. Each line comprises a property designator, a property type, and the values (as described above), separated by spaces. By default, if a single FMRI operand has been supplied, the property designator con- sists of the property group name and the property name joined by a slash (/). If multiple FMRI operands are supplied, the designator is the canonical FMRI for the property. A composed property may be selected directly from the entities which match a specified FMRI or from entities which may be used as a source of properties for these matching entities. An example of a composed property is a property which is set on a service, which may be selected when an instance matching an FMRI does not possess the property itself. An un-composed property selection is made against the specified FMRI with no further searching of additional sources of properties other than the entities which match the designated FMRI. Properties are displayed either with or without composition depending on the options which are supplied at invocation. Properties are com- posed by default. A snapshot, which is a point in time representation of the state of a matching entity's properties at a moment in time, always uses compo- sition because snapshots are always composed. Error messages are printed to the standard error stream. Many properties have specific meanings to the Service Management Facility or the service's restarter. The following options are supported: -C Retrieves the current property values, without composition. -c Retrieves the current property values, with composition. -f Designates properties by their FMRIs. Implies option -t. -p [name/]name Prints values of the named property or property group for each of the property groups, instances, or services spec- ified by the operands. -q Quiet. Produces no output. -s snapshot Uses the named snapshot to retrieve the specified property or property group, with composition (since snapshots are always composed). If the given property group is not present in the snapshot, the current property values are exam- ined. -t Uses the multi-property output format. -v Verbose. Prints error messages for nonexistent properties, even if option -q is also used. -w Waits for the selected property group or property to change before printing anything. This option is only valid when a single entity is given. If more than one operand is given, or an operand matches more than one instance, an error message is printed and no action is taken. The -w option always causes svcprop to operate against current property values. The following operand is supported: FMRI With no -p options, FMRI operands can name a service, instance, property group, or property. For services, service instances, and property groups, all contained properties are selected. Instances and services can be abbreviated by specifying the instance name, or the trailing portion of the service name. Properties and property groups must be specified by a full FMRI. For example, given the FMRI: svc:/network/smtp:sendmail The following are valid abbreviations: sendmail :sendmail smtp smtp:sendmail network/smtp The following are invalid abbreviations: mail network network/smt Abbreviated forms of FMRIs are unstable and should not be used in scripts or other permanent tools. Arguments to the -p option can name property groups or properties. In the former case, operands can name services or instances, and all properties in the named property group of the named services or instances are printed. In the latter, operands can name services, instances, or property groups, and the named properties belonging to the operands are printed. By default, all properties are selected from the running snapshot, with composition. If there is no running snapshot, then current properties are selected. The -w and -s options can be used to change the source of properties. When walking properties, that is, no -p options, current nonpersistent property groups are also selected. With -p options, if the property group doesn't exist in the running snapshot, then if the property group is nonpersistent the current property or property group is selected. Example 1: Displaying the Value of a Single Property The following example displays the value of the enabled property in the general property group of instance default of service inetd. example% svcprop -p general/enabled network/inetd:default true Example 2: Displaying All Properties in a Property Group This example displays all properties in the general property group of service ntp. example% svcprop -p general ntp general/entity_stability astring Unstable general/single_instance boolean true Example 3: Verifying the Existance of a Property This example verifies the existence of the general/enabled property for all instances of service identity. example% svcprop -q -p general/enabled identity: example% echo $? 0 Example 4: Waiting for Property Change This example waits for the sendmail instance to change state. example% svcprop -w -p restarter/state sendmail Example 5: Using svcprop in a Script example% cat getval #!/bin/sh svcprop -p $1 $2 | ( read value v2 if [ -n "$v2" ]; then echo "Multiple values!"; exit; fi echo $value ) The following exit values are returned: 0 Successful completion. 1 An error occurred. 2 Invalid command line options were specified. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ svcs(1), inetd(1M), svcadm(1M), svccfg(1M), svc.startd(1M), service_bundle(4), attributes(5), smf(5), smf_method(5), smf_security(5) 18 Mar 2005 svcprop(1)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy