Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Shell script using Diff

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-23-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 16 January 2015, 7:26 AM EST
Posts: 159
Thanks: 35
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 Unix and Linux 05-02-2010
pseudocoder's Unix or Linux Image
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 Unix and Linux 05-02-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 16 January 2015, 7:26 AM EST
Posts: 159
Thanks: 35
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 Unix and Linux 05-03-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 4 August 2015, 6:17 AM EDT
Location: The Netherlands
Posts: 7,731
Thanks: 129
Thanked 547 Times in 515 Posts
Is the the space between the "-" and "eq" a typo?


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

Sponsored Links
    #5  
Old Unix and Linux 05-03-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 16 January 2015, 7:26 AM EST
Posts: 159
Thanks: 35
Thanked 1 Time in 1 Post
Yes! you are right.
Sponsored Links
    #6  
Old Unix and Linux 05-03-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 4 August 2015, 6:17 AM EDT
Location: The Netherlands
Posts: 7,731
Thanks: 129
Thanked 547 Times in 515 Posts
Quote:
Originally Posted by DallasT View Post
Yes! you are right.
Not clear if your problem is solved now.Linux

Was it a typo in your original script?
Sponsored Links
    #7  
Old Unix and Linux 05-03-2010
DallasT DallasT is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 16 January 2015, 7:26 AM EST
Posts: 159
Thanks: 35
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.Linux

Was it a typo in your original script?

Last edited by DallasT; 05-03-2010 at 09:15 AM..
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:21 PM.