I've crated the next script in order to find a lock file's age:
#!/bin/bash
now=`date +"%T"`
lock="aggregator.lock"
find . -name $lock -type f
if [ $? != 0 ];
then
exit
else
ls -ltrh $lock 2&>/dev/null
fi
if [ $? != 0 ];
then
locktime=`ls -ltrh aggregator.lock |awk -F" " '{print $7}'`
else
echo "File not found"
fi
I have two problems:
- The output of
ls -ltrh aggregator.lock |awk -F" " '{print $7}'
gives me the time in format HH:MM rather than HH:MM:SS and the output ofdate +"%T"
gives me the time in format HH:MM:SS (As needed), so how can I get the modify time of the file with seconds? - I don't know how to subtract between the times... I wanted to do something like
$now - $locktime
in order to get the seconds delta between both variables, how can it be done?
EDIT: The meaning of the script is to find how long the lock file existed... There's this script:
device0="/home/build/aggregator/scripts/aggregator.lock"
if [ -e "$device0" ]
then
echo process is allready running
else
touch $device0
java -Xms6g -Xmx6g -jar /home/build/aggregator/aggregator-1.0-SNAPSHOT-jar-with-dependencies.jar
rm $device0
fi
Which creates the lock file... the only purpose of the creation of the lock file is to give me an indication about how long was the script's run time, just thought this information is needed as well, because I'm not looking for how much time passed since the last modification of the file.
Thanks in advance