Shell script using Diff | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Shell script using Diff

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-23-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 20 June 2014, 2:16 PM EDT
Posts: 152
Thanks: 30
Thanked 1 Time in 1 Post
Shell script using Diff

Hello - I have a small diff script that checks 2 directories. It reports the difference in count such as wc -l, and also names the different files.

How should I get "ERROR: diff found . (host)" - when it actually finds a diff?


This is how I have written:


Code:
#!/bin/bash

            DIFF=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only | wc -l)
            DIFF2=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only)
                        echo "The file count difference between master folder and CE-B-CM\D folder is:
${DIFF}"
            
            
            echo "The names of the different files and their paths are:
${DIFF2}."

            echo "####################################################"


Last edited by DallasT; 04-23-2010 at 12:30 PM..
Sponsored Links
    #2  
Old 05-02-2010
pseudocoder's Avatar
pseudocoder pseudocoder is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 17 February 2012, 6:42 AM EST
Location: /home/sea
Posts: 602
Thanks: 40
Thanked 83 Times in 81 Posts

Code:
#!/usr/local/bin/bash

DIFF=$(diff -r /path/to/dir1 /path/to/dir2)

if [[ $DIFF != "" ]]; then
echo "ERROR: diff found. $HOSTNAME"
fi

Sponsored Links
    #3  
Old 05-02-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 20 June 2014, 2:16 PM EDT
Posts: 152
Thanks: 30
Thanked 1 Time in 1 Post
That is only giving me my own local host name. Not the path to the host where the difference is found and the count...

i use this script, however, I am not able to flag the email subject line to either ERROR or GOOD, have a look:


Code:
#!/bin/bash
# Diff script to be used for file comparisions

DIFF=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | wc -l) 
if [ $DIFF -ne 0 ]
then
echo "ERROR: Diff found a diff in total count of this many files: ${DIFF}."
forproblemmail=1
else
echo "No Difference"
fi

DIFF2=$(diff -r /home/student/bin/dir1 /home/student/bin/dir2 | grep Only)
if [ $? -eq 0 ]
then
echo "The names of the different files and their paths are:
${DIFF2}."
forproblemmail=1
else 
echo "No files are different"
fi

#Email Module
if [ $forproblemmail - eq 1 ] ; then
       SUBJECT="ERROR: Problem During Diff"
         else
              SUBJECT="GOOD: Complete Find Files With Success"
fi
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE


Last edited by DallasT; 05-02-2010 at 10:01 PM..
    #4  
Old 05-03-2010
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 25 July 2014, 4:14 PM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 Posts
Is the the space between the "-" and "eq" a typo?


Code:
if [ $forproblemmail - eq 1 ] ; then

Sponsored Links
    #5  
Old 05-03-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 20 June 2014, 2:16 PM EDT
Posts: 152
Thanks: 30
Thanked 1 Time in 1 Post
Yes! you are right.
Sponsored Links
    #6  
Old 05-03-2010
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 25 July 2014, 4:14 PM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 Posts
Quote:
Originally Posted by DallasT View Post
Yes! you are right.
Not clear if your problem is solved now.

Was it a typo in your original script?
Sponsored Links
    #7  
Old 05-03-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 20 June 2014, 2:16 PM EDT
Posts: 152
Thanks: 30
Thanked 1 Time in 1 Post
Actually I am not sure if the way I flagged the error by "forproblemmail=1" , would really flag for the subject line of the email?

Also I am getting this when I run it:


Code:
line 24: [: -eq: unary operator expected

Quote:
Originally Posted by Franklin52 View Post
Not clear if your problem is solved now.

Was it a typo in your original script?

Last edited by DallasT; 05-03-2010 at 09:15 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Process diff command output in a shell script bhaliyajalpesh Shell Programming and Scripting 4 12-11-2009 04:25 AM
Shell script to manipulate a message count for the same IP @ diff session gobinath Shell Programming and Scripting 1 05-28-2008 03:13 PM
Is there a diff way to exec this shell prg?? kumarsaravana_s Shell Programming and Scripting 3 06-27-2007 09:37 AM
shell scripting my own diff command axcxe UNIX for Dummies Questions & Answers 4 12-11-2003 01:20 AM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 11:29 AM



All times are GMT -4. The time now is 09:05 PM.