Solved

if command (using diff in bash) question

Posted on 2009-07-13
3
849 Views
Last Modified: 2013-12-26
Hello,

The following code is indicating that the files match every time even if they don't -- what am I doing wrong?

Thank you!!
# !/bin/sh
 

LOG_FILE=/opt/depots/build/audit/$HOSTNAME.audit
 

if [ "diff -b -B -I ^# /etc/snmp/snmpd.conf /opt/depots/build/master/snmpd.conf" ]  ; then

   echo "pass   snmpd.conf matches Master file"

else

   echo "FAIL   snmpd.conf does not match Master file"

fi

Open in new window

0
Comment
Question by:EEK2
  • 2
3 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 24845229
Change

if [ "diff -b -B -I ^# /etc/snmp/snmpd.conf /opt/depots/build/master/snmpd.conf" ]  ; then

to

if [ diff -b -B -I ^# /etc/snmp/snmpd.conf /opt/depots/build/master/snmpd.conf > /dev/null ]  ; then

0
 
LVL 3

Assisted Solution

by:glenthorne
glenthorne earned 100 total points
ID: 24845230
You can try the following:

diff -b -B -I ^# /etc/snmp/snmpd.conf /opt/depots/build/master/snmpd.conf > /dev/null 2>&1
retval=$?
if [ $retval == "0" ]; then
   echo "pass   snmpd.conf matches Master file"
else
   echo "FAIL   snmpd.conf does not match Master file"
fi
0
 
LVL 58

Accepted Solution

by:
amit_g earned 400 total points
ID: 24845235
Ah.. it should be

if diff -b -B -I ^# /etc/snmp/snmpd.conf /opt/depots/build/master/snmpd.conf > /dev/null  ; then
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parse .log file for SQL import 13 58
Exchange 2010 get-mailbox and get-mailboxstatistics 10 194
incorrect file reading in bash 7 80
IE 11 + long running scripts 3 28
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now