Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4383056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:51:30+00:00 2026-05-21T12:51:30+00:00

Shell newbie here. I’m not sure what I am doing is a good way

  • 0

Shell newbie here. I’m not sure what I am doing is a good way to go about this.

Basically this is what i want to do:

  1. create a list of current directories (curr.lst)
  2. do a diff with the curr.lst and the old list (before.lst)

  3. if there is no difference, then ok no change, change the curr.lst to before.lst for next time it runs

  4. if there the diff.lst is greater than 0 bytes (meaning there is a change, then do something, mail the list of changes, etc.

Anyways,
My logic isn’t quite right. It could be my use of if statments.

I’m looking for help to either tweak my logic, better coding practice to do this simple task. Really all I want to do is have this script run daily and check if there is changes between the old and the new, if there is a change, i want to know.

Thanks for any input, suggestions, examples.

#!/usr/local/bin/bash
STAGE=/myproj/foo/proc
BASE=/dev/testing/scripts

BEFORE="$BASE/before.lst"
CURR="$BASE/curr.lst"
DIFFOUT="diff.out"

CHKSZ=`du -k "$BASE/$DIFFOUT" | cut -f 1`

#MAIN
if [ -f $BEFORE ]; then #if we find a previous file to compare enter main loop, if not get out
          chmod 755 $BEFORE
          echo "old list exists"  2>&1
          echo "get the new list and do a diff"  2>&1
          ls "$STAGE" | perl -nle 'print $1 if m|$STAGE/(\S+)|' > "$CURR" #creates a file curr.lst

          #if curr.lst exists then do the diff
          if [ -f $CURR ]; then
             diff -b -i $BEFORE $CURR >> $BASE/$DIFFOUT 2>&1 #create file diff.out
          else
             echo "command did not work, no diff.out file to compare, exiting..." 2>&1
          exit 0
          fi

          #if file diff.out exists, check its file size, if its greater than 0 bytes then not good 
          if [ -f $BASE/$DIFFOUT ]; then
              echo "diff.out exists, how big is it?" 2>&1
              chmod 755 $BASE/$DIFFOUT
              $CHKSZ #run check on file size
          else
              echo "Could not find diff.out" 2>&1
          exit 0
          fi

          if [ $CHKSZ == "0" ]; then
                echo "no changes to report" 2>&1
                rm $BASE/$DIFFOUT #Cleanup the diff since there's notthing to report
                mv $CURR $BEFORE #change curr.lst to before.lst to compare next time
          else
                echo "Detected a change" 2>&1
                echo "Report it" 2>&1
          exit 0
          fi
else
echo "No before file to compare" 2>&1
exit 0
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:51:30+00:00Added an answer on May 21, 2026 at 12:51 pm

    One thing I see is that you already execute $CHKSZ (resp. du -k ...) in line 9 of you script. The command in backticks is executed immediately.

    A second problem might be that you use du -k which prints the size in kilobites. If there are only minor changes you might get a size of 0. I guess you better use du -b to get the size in bytes (if you want to do it in this way).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a shell script newbie. I want to know the difference between ${var%pattern}
The following shell script takes a list of arguments, turns Unix paths into WINE/Windows
I'm an Eclipse newbie and I'm trying to build a mixed AWT/SWT application. Here's
I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here .
I am a newbie for shell script. I noticed that for command like: tar
Here is a shell script: echo Starting Jarvis Program D. ALICE_HOME=. SERVLET_LIB=lib/servlet.jar ALICE_LIB=lib/aliceserver.jar JS_LIB=lib/js.jar
I'm making a shell script and I want to know if it's possible to
Android developer newbie here. I am trying to develop a GUI wrapper in Android
I think I searched for an answer about my problem but I did not
I am a newbie to eclipse plugin development. I want to implement a plugin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.