fileintegrity.sh
26 linesbash
DOWNLOAD
1#!/bin/bash
2# Aim: Program to perform file integrity check (File Integrity Check).
3echo 'To test the integrity of the file in a directory at '$PWD
4read -p "Enter the name of the file : " file
5calculate_hash() {
6    sha256sum $1 | awk '{print $1}'
7}
8if [ ! -f $file ]; then
9    echo "File not found!"
10    exit 1
11fi
12
13oghash=$(calculate_hash $file)
14echo "Original hash: $oghash"
15
16# Wait for user to modify the file
17read -p "Press enter when you have modified the file..."
18
19newhash=$(calculate_hash $file)
20echo "New hash: $newhash"
21
22if [ "$oghash" == "$newhash" ]; then
23    echo "File integrity is intact."
24else
25    echo "File has been modified."
26fi