LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-14-2010, 10:54 AM   #1
aircftech
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Rep: Reputation: 0
compare directory to .txt or .xml???


I have a database of around 4000 files. I use rsync script to transfer from 2 separate updated hdd every month but I need a way to compare a .txt file or .xml file to the updated drive as I cannot use rsync delete because I can not mount all 3 drives at the same time??

Thanks for any help.
 
Old 12-14-2010, 11:01 AM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,101

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
you cant mount all 3 drives at the same time? why not?
 
Old 12-14-2010, 11:03 AM   #3
aircftech
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Original Poster
Rep: Reputation: 0
they come on 2 separate hdd and I only have 1 slot. figures right.
 
Old 12-14-2010, 11:10 AM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,101

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
just an idea (if you have a few bucks to spare) usb to ide/sata adapters run about $20 USD give or take
just a thought

as for synchronizing, you could do something like
Code:
ls > list.txt
once you have a list then create a text file named say, sync.sh
put in it
Code:
#!/bin/bash
for file in `cat list.txt`
do
copy $1/$file $2/$file
done
then chmod +x sync.sh and invoke it with
[code]
$./sync.sh /source/path /destination/path
assuming the list is one file name per line in the text file that is

Last edited by frieza; 12-14-2010 at 11:12 AM.
 
Old 12-14-2010, 11:21 AM   #5
aircftech
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Original Poster
Rep: Reputation: 0
not really a option. I have everything all set with a rsync script I just need to remove the old file about 20 of them. but I have the compare Dir1 to a .txt or .xml file some how.

I thought "diff" could do this???

Last edited by aircftech; 12-14-2010 at 11:31 AM.
 
Old 12-14-2010, 03:25 PM   #6
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,101

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
no, diff compares the contents of files line by line, useful for say, applying patches to source code, but doesn't seem to be what you are looking for, it seems at least what you need is something that provides a list of files you want updated, files you want ignored, files you want removed and then something that does a loop and acts accordingly
 
Old 12-14-2010, 04:39 PM   #7
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Lightbulb

Okay, this should just about do it. Was getting all tangled up reading 2 different files... Anyhow, this will read a filename from the old_file_list file and grep the new_file_list file for the file name retrieved. If it succeeds in finding the file name in the new file list then grep will return data in my_result, i.e. the my_result file will now be greater than zero size. Now test and if my_result IS zero size the file name returned from the old_file_list doesn't exist in the new file list so delete the file from the old_file_list path.
Code:
#!/bin/bash
cat old_file_list | while read
do
  grep "$REPLY" new_file_list >> my_result
  if [ ! -s my_result ]
  then
    rm /old_backup_path/"$REPLY"
  fi
  rm my_result
done

exit 0

Last edited by barriehie; 12-14-2010 at 10:35 PM.
 
Old 12-15-2010, 07:36 AM   #8
aircftech
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Original Poster
Rep: Reputation: 0
ok I have the output I want from creating to .txt files and running


comm -13 /home/dir1/mediaload.txt /home/dir2/mediaload.txt

returns the file names I need to delete. Any idea on how I can do that??

Thanks for the help.
 
Old 12-15-2010, 08:39 AM   #9
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Post the code you're using!
 
Old 12-15-2010, 12:14 PM   #10
aircftech
LQ Newbie
 
Registered: Dec 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Sovled

I did this for both Hdd-----

zenity --question --text "Do you want to copy CRU1 to array1 ?"
if [ $? == 0 ] ; then
cp /media/cru/mediaload.txt /media/array1
rsync -a /media/cru /media/array1 | tee >(zenity --progress --title "Tranfer" --text "Coping file from CRU1 to ARRAY. Get a cup of coffee" --percentage=0 )
notify-send 'Please shut down and install CRU2 and run TranferCRU2'
else
notify-send 'Please try again something went wrong'
fi

then i did-------

zenity --question --text "Do you want to Delete old files??"
if [ $? == 0 ] ; then
comm -13 /home/dir1/mediaload.txt /home/dir2/mediaload.txt | xargs -I '{}' rm /home/dir2/'{}'
notify-send 'Please run Verify on Media'

else
notify-send 'Thank You GoodBye!'
fi

with 1tb of info I didn't have enough space to hold to copies and do a simple cp or rm.

thanks for the suggestions.
 
  


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
Bash script to compare numbers in a txt file leopard86 Programming 6 09-11-2012 12:10 AM
in shell scripting how to compare strings from two different simple .txt files tej16 Linux - Newbie 1 07-29-2010 02:34 AM
Using key to match against source.txt file to add xml tags to names in Perl ginny2010 Programming 3 06-22-2010 01:16 PM
Java code to compare XML like ExamXML alapick Programming 1 06-29-2006 05:43 AM
How to convert xml version of LFS-5.1.1 book to txt format? jml75 Linux From Scratch 1 06-18-2004 06:51 PM


All times are GMT -5. The time now is 11:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration