Monday, February 27, 2017

Bash Scripting: Checking Directory and File

#!/bin/bash
#
location=$HOME
filen="sentinel"
#
if [ -e $location ]
then
        echo "Ok on the $location directory"
        echo "Now checking on the file, $filen"
        #
        if [ -e $location/$filen ]
        then
                echo "OK on the filename"
                echo "Updating Current Date..."
                date >> $location/$filen

        #
        else
                echo "File does not exist"
                echo "Nothing to update"
        fi

#
else
        echo "The $location directory does not exist"
        echo "Nothing to update"
fi

No comments:

Post a Comment