This will virtually get you there, this will check if a file has been accessed since the last boot.
#!/bin/bash
unixTimestamp () {
date --utc --date "$1" +%s
}
if [ "$1" == "" ];then
echo "You must specify a filename (e.g. './lastRun.sh foobar.sh')"
exit 255
fi
FILENAME=$1
if [ -f ${FILENAME} ]; then
if [ -n ${FILENAME} ]; then
LASTRUN=`ls -laru ${FILENAME}|cut -f6,7,8 -d' '|sed 's/'${FILENAME}'//g'|sed 's/^ *//;s/ *$//'`
LASTBOOT=`who -b|sed 's/.*system boot//g'|sed 's/^ *//;s/ *$//'`
echo "Last Run: '${LASTRUN}'"
echo "Last Boot: '${LASTBOOT}'"
if [ "$(unixTimestamp ${LASTRUN})" -lt "$(unixTimestamp ${LASTBOOT})" ]; then
echo "${FILENAME} has not been run since last boot."
exit 1
else
echo "${FILENAME} has been run since last boot"
exit 0
fi
fi
else
echo "Unable to find file '${FILENAME}'..."
exit 255
fi
If you have run the file it will have been accessed, but it also may have been edited by somebody and not run, or maybe touched.
EDIT
A bit of explanation:
LASTRUN=ls -laru ${FILENAME}|cut -f6,7,8 -d' '|sed 's/'${FILENAME}'//g'|sed 's/^ *//;s/ *$//'
For the above command:
ls -laru ${FILENAME}|cut -f6,7,8 -d' ' # Will take the filename and display the last access time
|sed 's/'${FILENAME}'//g' # Will strip the filename out to leave you with the date and time
|sed 's/^ *//;s/ *$//' # Will strip out whitespace before and after the date/time
This will leave you a date/time ready to convert to a unix timestamp
LASTBOOT=who -b|sed 's/.*system boot//g'|sed 's/^ *//;s/ *$//'
For the above command:
who -b # Will show the time the system last booted
|sed 's/.*system boot//g' # Will strip out the text "system boot" to leave you with a date/time
|sed 's/^ *//;s/ *$//' # Will strip out whitespace before and after the date/time
This will leave you a date/time ready to convert to a unix timestamp
the unixTimestamp function takes the Date/TIME variable and converts it to a unix timestamp and then it's just a case of seeing which is the higher number. The higher number is the most recent, so we can work out if the last thing that happened was a reboot or a file access.