Find the answer to your Linux question:
Results 1 to 4 of 4
Hello Everyone! I am very new to BASH scripting and was hoping for some help. I am working on a project for my Linux class, and am quite confused. We ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    17

    New to BASH scripting help


    Hello Everyone!

    I am very new to BASH scripting and was hoping for some help. I am working on a project for my Linux class, and am quite confused. We each need to design our own advanced BASH script. This is what I thought of I would like to have a text file act as a database with MD5 sums of files placed in there. Then when you fire up the shell script it references that file and then searches all files for a match with that MD5. After finding a match it then moves those file files into a folder. I figure they could search for a couple of text documents that I created. I am familar with grep, read, and the md5sum commands. I just do not know how to pull this together. Maybe this is not even possible with BASH, but any help would really be appreciated.

    Thanks

  2. #2
    Just Joined!
    Join Date
    Jul 2012
    Posts
    17
    It looks like md5deep may be more appropriate for this. Anyone agree?

  3. #3
    Just Joined!
    Join Date
    Apr 2013
    Posts
    40
    Quote Originally Posted by aaron9615 View Post
    Hello Everyone!

    I am very new to BASH scripting and was hoping for some help. I am working on a project for my Linux class, and am quite confused. We each need to design our own advanced BASH script. This is what I thought of I would like to have a text file act as a database with MD5 sums of files placed in there. Then when you fire up the shell script it references that file and then searches all files for a match with that MD5. After finding a match it then moves those file files into a folder. I figure they could search for a couple of text documents that I created. I am familar with grep, read, and the md5sum commands. I just do not know how to pull this together. Maybe this is not even possible with BASH, but any help would really be appreciated.

    Thanks
    I've got a bash script that I use to remove files having duplicate contents but different filenames. Maybe you can modify it to suit your purposes. Here it is:

    Code:
    #!/bin/bash
    rm -f /tmp/sums.txt
    OLDIFS=$IFS
    IFS=$(printf "%b" "\n")
    for fn in *
    do
    if [ "$fn" != "mshowdupfiles" ]
    then
    if [ -d "$fn" ]
    then
    continue
    fi
    	echo $(md5sum "$fn") >> /tmp/sums.txt
    fi
    done
    sort /tmp/sums.txt > /tmp/srtdsums.txt
    linecount=0
    #for line in $(cat /tmp/srtdsums.txt)
    while read line
    do
    (( linecount++ ))
    if [ $linecount -eq 1 ]
    then
    	previousline=$line
    	previoussum=${line%% *}
    	continue
    fi
    currentline=$line
    currentsum=${line%% *}
    currentfile=${line##$currentsum  }
    if [ $currentsum == $previoussum ]
    then
    	rm -f $currentfile
    fi
    previousline=$currentline
    previoussum=$currentsum
    done < /tmp/srtdsums.txt
    IFS=$OLDIFS

  4. #4
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    hi BowCatShot,

    modifying the IFS is useless now you correctly parse the file using a `while' loop.
    also, remove commented code, please.

    and no temporary files should be left on the system the script is running on at the end of this script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •