You are not logged in.

#1 2005-10-23 09:03:50

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Time counting

In Bash, how to get a file deleted not less than 1 hour?

last-exit-time=`cat  /test/time.txt`
if [ $current-time above-1h $last-exit-time ]; then
rm -f /test/file.tmp
fi


Markku

Offline

#2 2005-10-23 12:14:42

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Time counting

-gt   greater than
-lt     less than
-eq   equal to
-ge   greater than or equal to
-le    less than or equal to

assuming you have $current-time already defined:

if [ $current-time -gt $last-exit-time ]; then
rm -f /test/file.tmp
fi

Offline

#3 2005-10-23 14:54:59

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Time counting

How about using the at daemon?

something like this (not sure of the exact syntax):

at now+1h rm -f /test/file.tmp

If its a repetitive job, of course you would use cron.

Dusty

Offline

#4 2005-10-23 18:47:59

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: Time counting

Dusty wrote:

If its a repetitive job, of course you would use cron.

This is for the PacTK, which is not that great as pacman.:) Instead of downloading each time the latest package list from ArchWD repo, when installing a package, the script will do it only once. If the user installes after one hour or just want to see what's available, then the list will be downloaded again.

Thanks Penguin, got it working.

TMP="$HOME/.fvwm/archwd-user/tmp"
date +%s -d "1 hour" > $TMP/latestlist.tmp

if [ -f $TMP/latestlist.tmp ]; then
Last=`cat $TMP/latestlist.tmp`
date +%s > $TMP/now.tmp
Now=`cat $TMP/now.tmp`
if [ "$Now" -gt "$Last" ]; then
rm -f $TMP/latestlist.tmp
rm -f $TMP/now.tmp
fi
fi

Markku

Offline

Board footer

Powered by FluxBB