How to do it...

  1. We are going to write a script to check whether a file in a directory has been tampered with. Create an integrity_check.sh script and add the following code to it:
#!/bin/bashE_DIR_NOMATCH=50E_BAD_DBFILE=51dbfile=Filerec.md5# storing records.set_up_database (){    echo ""$directory"" > "$dbfile"    # Write directory name to first line of file.    md5sum "$directory"/* >> "$dbfile"    # Append md5 checksums and filenames.}check_database (){    local n=0    local filename    local checksum    if [ ! -r "$dbfile" ]    then        echo "Unable to read checksum database file!"        exit $E_BAD_DBFILE    fi    while read rec[n]    do        directory_checked="${rec[0]}"        if [ "$directory_checked" != "$directory" ]        then            echo "Directories do not match up!" # Tried to use file for a ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.