Bash script to compare two files
I'm trying to tell if two files are different in a script.
I'm trying to use diff or md5sum to check if they are different but I can't process the output of it easily. So what I want is Code:
if [ file1 == file2 ]; then |
The following tests whether the 2 files are different (they must exist). Is that what you want to do?
Code:
#!/bin/sh |
Thanks a lot.
|
what does that ">/dev/null" do?
im using this line and it seems to be working.. i just dont know what that does :) |
"/dev/null" is often called the null device or the bit bucket. /dev/null is a special file that the OS considers a device. it consumes all input sent to it, kind of like a black-hole star.
rgds bil |
thanks, i finally got my script working too :)
-Sui |
basiacally if you dont pipe the output of diff to the bottemless pit that is /dev/null
it spews all sorts of stuff out (like exactly how the files differ) |
I found this link via google
this did not work for me, but the following did: Code:
#!/bin/bash I was using fedora core 5 when i tried this, it failed, and i came up with the above code. Just dont want someone in my shoes to come across this and get royally pwnd if/when the suggested solution fails I wrote a script to convert .forward files into .procmailrc files so that my spamassassin does not get bypassed when people use vacation reply messages, because it seems .forward skips procmail processing, and so the user gets tons of spam while on vacation, and comes back with 300+ mailer-daemon messages saying their auto response failed to send, and any spams they did respond to that didnt fail most likely will mean more spam lists they've gotten themselves onto. really all i was doing is checking all homedirs for .forward files, if it found any it would iterate thru them all, compare an existing .procmailrc if applicable to ":0 c" concatenated to the .forward file, and if different or non-exstant it would rewrite the file, if found and the same it would not. it may be more efficient to just always delete and rewrite the file but if the user receives an email at the very instant between deletion and recreation there would be no .procmailrc file perhaps, and I am not about to test whether or not this can happen, so I am assuming it would. if you want my whole file, here it is: (note: will only handle user dirs that are /home/USERNAME, will not handle any that are outside of this. i suppose you could parse /etc/passwd instead if you really wanted, but if you were going to get that good you might as well find a more elegant solution in the first place!) Code:
#!/bin/bash |
since unix bases everything on files, whether it be sockets, pipes or files diff will compare them.
|
I tried the exact code offered on the forum and it did not work for me on Fedora Core 5.
It seemed that diff WAS comparing the files, but was returning the same return code regardless of whether the files were different or not. If it works for you, fine, if not, maybe my solution will. |
Quote:
Thanks so much for this I'm just a linux newbie and it has made my life easier. I used this to compare 2 checksums, to make sure the secure copy was completed successfully. |
bash script
thnk you very much..
|
Code:
#!/bin/sh |
Bad substition error
Based on the solution this thread provided, I employed it do a task and I'm baffled by something. The purpose of the script is to compare 2 files on a system. Somehow a tree structure was copied and am fairly certain that the files are identical
The command line is as follows: Code:
./filecomp.sh /home/daniel/Documents/workspace/www/ Code:
find $1 -name "*.*" | while read file If I run the file with bash -x to echo the steps for debugging, it works fine. If I don't debug, then I receive an error of Bad Substitution at line 10 (the last line of the script). Can anyone advise? |
Sounds very odd; have you considered amending debug to
Code:
set -xv Possibly you have a space or other invisible char in a filename somewhere? |
All times are GMT -5. The time now is 04:10 PM. |