I found the following script to find the age of the lock file:
#!/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:
- Exiting
ls -ltrh aggregator.lock |awk -F" " '{print $7}'
gives me time in HH: MM format, not HH: MM: SS and exiting date +"%T"gives me time in HH: MM: SS format (as needed), so how can I get the file modification time in seconds? - I donβt know how to subtract between times ... I wanted to do something like
$now - $locktimeto get the delta of seconds between both variables, how can this be done?
EDIT: The value of the script is to find how long the lock file has existed ... There it is a 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
... - , script, , , m , .