Script for Comparing directories and file from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for Comparing directories and file from a text file
# 1  
Old 02-22-2013
Script for Comparing directories and file from a text file

Hello all,
I need to write a script which has following requirement:

Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder.
And also need to compare and verify whether the files in the two directories are same.
(need to verify time stamps and files sizes too.)

The text file is like below :
Quote:
SecurityProviders/ldapSecurityProvider.lsl Message Broker File
SecurityProviders/tfimSecurityProvider.lsl Message Broker File
bin/bipbroker Message Broker File
bin/bipservice Message Broker File
cachesupport/lib/cachesupport.jar Message Broker File
classes/connectors.jar Message Broker File
lib/libImbCmdLib.so Message Broker File
lib/libImbRdl.so Message Broker File
lib/libJDBCType4JNISinglePhaseTrxn.so Message Broker File
lib/libJMSJNILocalTrxn.so Message Broker File
lib/libMQLibrary.so Message Broker File
lib/libMbAdapterJNISinglePhaseTrxn.so Message Broker File
Please help.
# 2  
Old 02-22-2013
Code:
 
while read f x
 do
  if [ ! -f $f ]
   then
    echo No $f
    continue
   fi
  if [ "$(cmp $f backup_place 2>&1)" = "" ]
   then
    echo Already same: $f
    continue
   fi
  cp -p $f backup_place/$f
  if [ $? = 0 ]
   then
    echo Backed up: $f
   else
    echo FATAL Backup error: $f
    exit 1
   fi
 done < list

# 3  
Old 02-25-2013
Thanks DGPickett,

Actual script to be written as :

Quote:
readmes/8.0.0.1-WS-MB-LinuxX64-TFIC89508-README.txt This Readme file
SecurityProviders/ldapSecurityProvider.lsl Message Broker File
SecurityProviders/tfimSecurityProvider.lsl Message Broker File
bin/bipbroker Message Broker File
bin/bipservice Message Broker File
cachesupport/lib/cachesupport.jar Message Broker File
classes/connectors.jar Message Broker File
lib/libImbCmdLib.so Message Broker File
lib/libImbRdl.so Message Broker File
lib/libJDBCType4JNISinglePhaseTrxn.so Message Broker File
lib/libJMSJNILocalTrxn.so Message Broker File
lib/libMQLibrary.so Message Broker File
lib/libMbAdapterJNISinglePhaseTrxn.so Message Broker File
lib/libMessageServices.so Message Broker File
lib/libSCANodes.so Message Broker File
lib/libTemplateNodes.so Message Broker File
lib/libWSLibrary.so Message Broker File
lib/libbipmain.so Message Broker File
lib/libconnectors.so Message Broker File
lib/libimbdfeda.so Message Broker File
lib/libimbdfplg.so Message Broker File
lib/libimbdfxci.so Message Broker File
lib/libimbjplg.so Message Broker File
lil/imbadpmgr.lil Message Broker File
lil/imbdfagg.lil Message Broker File
lil/imbdfbas.lil Message Broker File
lil/imbdfcfg.lil Message Broker File
lil/imbdfcon.lil Message Broker File
lil/imbdfjmt.lil Message Broker File
lil/imbdfjps.lil Message Broker File
lil/imbdfmqe.lil Message Broker File
lil/imbdfmqm.lil Message Broker File
lil/imbdfpgi2.lil Message Broker File
lil/imbdfsca.lil Message Broker File
lil/imbdfscada.lil Message Broker File
lil/imbdfsql.lil Message Broker File
lil/imbdfws.lil Message Broker File
lil/imbdotnetmgr.lil Message Broker File
lil/imbesqlmgr.lil Message Broker File
lil/imbidlmgr.lil Message Broker File
lil/imbjcomp.lil Message Broker File
lil/imbjplug2.lil Message Broker File
lil/imbjsonparser.lil Message Broker File
lil/imbmapmgr.lil Message Broker File
lil/imbpep.lil Message Broker File
lil/imbphpmgr.lil Message Broker File
lil/imbschemamgr.lil Message Broker File
lil/imbsiebel.lil Message Broker File
lil/imbtimer.lil Message Broker File
lil/imbtnp.lil Message Broker File
lil/imbwsdlmgr.lil Message Broker File
lil/imbwtxmgr.lil Message Broker File
lil/imbxmlmgr.lil Message Broker File
lil/imbxsdmgr.lil Message Broker File
lil/imbxslmgr.lil Message Broker File
migration/imbdfmignd.lil Message Broker File


Instructions for Message Broker File files:
1. Ensure all Brokers are stopped, using mqsistop, on the machine that the fix is being applied to.
2. Backup the above files under the Message Broker's installation directory ensuring that you change their extensions or move them to a backup directory. For example, change .lil files to .lil_bak or .lil_fp99 and jar files to .jar_bak or .jar_fp99.
3. Copy the above libraries to the correct directories under the Message Broker's installation directory.
4. Ensure the owner/group details of the new files match those of the existing files. (chown)
5. Ensure the permissions of new files match those of the existing files. (chmod)
6. Use mqsistart to restart the Broker components.


-------------------
END of the file:

Need to read the filenames from this text file located at
/lpiwmbdev6/stage/APAR/IC89508/readmes/8.0.0.1-WS-MB-LinuxX64-TFIC89508-README.txt

Then search for the above read files in the directory /opt/ibm/mqsi/8.0 and if match found backup them in a folder
/lpiwmbdev6/stage/APAR/IC89508/backup.




After applying APAR need to verify whether the files in the two directories are same
/lpiwmbdev6/stage/APAR/IC89508/* is equal to the copied files in /opt/ibm/mqsi/8.0
(need to verify time stamps and files sizes here).
Please help.
# 4  
Old 02-26-2013
Does the search just compare name or content, too?
# 5  
Old 02-27-2013
It should compare the content, size and permission of all files and directories.
Please let me know if you have any further question.
# 6  
Old 02-27-2013
cksum is a nice way to detect different content. It prints size. ls and when available find -ls print permissions. It seems like some combination would do it. Do you care about directory size in bytes, or just new entries?
# 7  
Old 03-01-2013
Sorry for late reply,

Just new entries will be fine.

Please let me know if you have any further questions.

Regards,
Saurau
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (4 Replies)
Discussion started by: shadow_fawkes
4 Replies

2. Shell Programming and Scripting

**URGENT ** : Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (1 Reply)
Discussion started by: shadow_fawkes
1 Replies

3. Shell Programming and Scripting

Comparing 2 text files & downloading a file if the last lines are different

Hello I'm having a little difficulty in writing a shell script for a few simple tasks. First I have two files "file1.txt" and "file2.txt" and I want to read and compare the last line of each file. The files look like this. File1.txt File2.txt After comparing the two lines I would... (2 Replies)
Discussion started by: RustikGaming
2 Replies

4. Shell Programming and Scripting

Comparing text in 2 files and output difference in another file.

I have 2 files of almost same text apart from 2,3 ending lines. Now I want to get that difference in another file. e.g file1.txt is Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_livecd-lv_root 18G 2.4G 15G 14% / tmpfs 504M ... (12 Replies)
Discussion started by: kashif.live
12 Replies

5. Shell Programming and Scripting

Comparing a text file's entries with ps -ef output

Shell : Korn os : AIX This is the ps output looking for a process called pmon. pmon runs with various 'service' names which is appended with an underscore as shown below. For example a pmon process for the service hexjkm will be named ora_pmon_hexjkm $ ps -ef | grep pmon oracle... (1 Reply)
Discussion started by: kraljic
1 Replies

6. UNIX Desktop Questions & Answers

COMPARING COLUMNS IN A TEXT FILE

Hi, Good day. I currently have this data called database.txt and I would like to check if there are no similar values (all unique) on an entire row considering the whole column data is unique. the data is as follows cL1 cL2 cL3 cL4 a12 c13 b13 c15 b11 a15 c19 b11 c15 c17 b13 f14 with... (1 Reply)
Discussion started by: whitecross
1 Replies

7. UNIX for Dummies Questions & Answers

Comparing a number in a text file with a specific value

My project is to get a temperature reading from a refridgerator every 2 minutes and check to see if the door has been left open. I don't yet have the mastery of Linux, being a complete noob, but I reckon I need a text file with the latest temperature reading in it. This I've managed to do by... (2 Replies)
Discussion started by: Fitch
2 Replies

8. Shell Programming and Scripting

Comparing and Formatting the text file

hi, I need a script which can format the below text file which contains comments file1.txt -------- //START //Name: some value //Date: //Changes:............. //..................... //END //START //Date: //Name: some value //Changes:............. //..................... (3 Replies)
Discussion started by: flamingo_l
3 Replies

9. Shell Programming and Scripting

Reading text file and comparing the dates in Kshell

I have a text file in which holidays are listed as YYYYMMDD. Here is the sample data of the file. 20090911 20090912 20090913 I need to read this file and see if the current day is listed in this text file. If today and any of the rows in my text file match, I need to do further... (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

10. UNIX for Dummies Questions & Answers

Comparing file names to text document

Hi All, I'm really new to Unix scripts and commands but i think i'm eventually getting the hang of some of it. I have a task which is to create some kind of script which compares the file names in a directory, with the associated file name in a .txt file. We send out some data and Unix has a... (1 Reply)
Discussion started by: gman
1 Replies
Login or Register to Ask a Question