LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   file comparing (https://www.linuxquestions.org/questions/linux-server-73/file-comparing-753988/)

abhijeetdutta 09-09-2009 04:37 PM

file comparing
 
hi,

how to compare should be done between the files in the directory and the files on the server on different location if the file mismatch then it sent alert through bash script.

Thanks

TB0ne 09-09-2009 07:59 PM

Quote:

Originally Posted by abhijeetdutta (Post 3676438)
hi,

how to compare should be done between the files in the directory and the files on the server on different location if the file mismatch then it sent alert through bash script.

Thanks

Please write clearly, your question is very hard to follow. I *THINK* you're asking "How can I compare files on my local server, to the same files on a remote server, and send an alert if they're different"...is that right?

You can do an "ls -l" on a file locally, which will return the size/date, etc. On the remote, you can do it via ssh, like "ssh <user>@<address> 'ls -l <filename>'", then compare the two.

And if you want to do this through Bash, I will AGAIN suggest you look at any one of the thousands of bash tutorials that are available through Google.

abhijeetdutta 09-10-2009 05:29 PM

if you let me know those thousand of tutorial address it will helpful for me tb1....

colucix 09-10-2009 06:00 PM

You can also use the DRY RUN capability of rsync. In DRY RUN mode rsync will show a list of the files that are going to be syncronized (files mismatch) without actually performing any action (files stay out of sync). Here is an example:
Code:

rsync -av --dry-run -e ssh /path/to/source/dir/ user@host:/path/to/destination/dir/
If the files between the two server are exactly the same, you will get an empty list like this:
Code:

$ rsync -av --dry-run -e ssh /path/to/source/dir/ user@host:/path/to/destination/dir/
sending incremental file list

sent 180 bytes  received 15 bytes  390.00 bytes/sec
total size is 151  speedup is 0.77 (DRY RUN)

otherwise you will get a list of the files rsync would have copied to the remote server if not run in DRY mode:
Code:

$ rsync -av --dry-run -e ssh /path/to/source/dir/ user@host:/path/to/destination/dir/
sending incremental file list
./
file1
dir1/
dir1/file2
dir2/
dir2/file3

sent 207 bytes  received 42 bytes  498.00 bytes/sec
total size is 151  speedup is 0.61 (DRY RUN)

In this file list, paths are relative to the source dir. The example above translates to:
/path/to/source/dir/
/path/to/source/dir/file1
/path/to/source/dir/dir1/
/path/to/source/dir/dir1/file2
/path/to/source/dir/dir2/
/path/to/source/dir/dir2/file3

abhijeetdutta 09-10-2009 06:23 PM

actually i have wrote a script to download files from ftp...ater downloading it will verify that is any file missed during download on weekly basis...

TB0ne 09-10-2009 09:51 PM

Quote:

Originally Posted by abhijeetdutta (Post 3677974)
if you let me know those thousand of tutorial address it will helpful for me tb1....

http://www.google.com

Put in "bash script tutorial" Press "ENTER"


All times are GMT -5. The time now is 10:50 AM.