LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2012, 04:38 AM   #1
anon84
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Rep: Reputation: Disabled
Shell script to find out which properties are modified/added/deleted.


Hi Guys,

I am trying to write a shell script which will tell me which properties are modified/added or deleted.
Lets say I have the old property files in a folder /home/anon84/old_props and the new ones in a folder /home/anon84/new_props.The property file names are same in both folders.

Sample property in any property file (say test.properties)
sample_key_name = sample_key_value

I want my script to produce output like this:

Properties updated:
Propert File Name : test.properties
Key Name : test_key_name
old key value: test_key_old_value
new key value : test_key_new_value


New Properties Added:
Propert File Name : test.properties
Key Name : test_new_key_name
new key value : test_new_key_value


Old Properties Deleted:
Propert File Name : test.properties
Key Name : test_old_key_name
old key value : test_old_key_value

(Based on the criteria there might be multiple outputs in each section)

Any hint on how to get started on this will be highly appreciable.
 
Old 04-17-2012, 04:47 AM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
what do you have written so far? you'll find we are more readily willing to help sometime even complete the entire script for you once you have something you have done yourself.
 
Old 04-17-2012, 10:27 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Also the current description and examples are particularly vague and do not necessarily match up. ie how does a property file with 'sample_key_name = sample_key_value' relate to any of the
output you have requested??
 
Old 04-17-2012, 08:10 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 04-19-2012, 01:16 AM   #5
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Rep: Reputation: 0
Exclamation

I guess what he is trying to do is whatever changes someone does in a file should be reflected in a formatted manner after running the script.
I guess the flow would be, if the file is open for editing make a backup copy of that file(so that we can compare the contents) and then edit it and then compare both the files and whatever is the difference show that in the desired formatted way.

Question:
a) How can we instruct when the file is open for editing make a backup copy? (I guess some cron job should be running in the background continuously to check when the file is open for editing and make the backup copy immediately)
 
Old 04-19-2012, 02:16 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
As he's talking about writing script to do this, you'd backup data file first, before doing anything else.
To use shell I guess I'd use a data file with key, then name/value pairs for each key and have a special value for deleted value eg <DEL>, or possibly blank.
One rec per property & csv format possibly...
If you're going to want to keep history recs, possibly a DB would be better, or maybe I'd use Perl with Tied Hashes.
 
Old 04-19-2012, 02:53 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
abhinav4 would seem to be proving my point about the vagueness as all answers start with "I guess"...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me write shell script to check the modified date of a file. thinhnguyenduy79 Linux - Newbie 1 06-17-2011 05:14 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 10:59 AM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 03:49 AM
Running a shell script when a user is added. jayakrishnan Linux - General 5 04-29-2002 03:55 AM


All times are GMT -5. The time now is 12:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration