~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/tmp_manager -rw-r--r-- 773 bytes
fc214385Johan Vandegriff added other old scripts, some newer ones too 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
tmpdir=~/tmp
datafile=~/.tmpdata

timeout=10000     # 10 seconds
#timeout=86400000  # 1 day

delimiter='	'

now=`date +%s%N | cut -b1-13`

tmpdata=`cat "$datafile"`
> "$datafile"

echo "$tmpdata" | while read line
do
  filename=`echo "$line" | cut -f1 -d"$delimiter"`
  if [[ ! -z "$filename" ]]
  then
  if [[ -f "$tmpdir/$filename" ]] || [[ -d "$tmpdir/$filename" ]]
  then
    date_noticed=`echo "$line" | cut -f2 -d"$delimiter"`
    if [[ $(($date_noticed + $timeout)) -lt "$now" ]]
    then
      rm -r "$tmpdir/$filename"
    else
      echo "$line" >> "$datafile"
    fi
  #else
  #  echo "file missing: $filename"
  fi
  fi
done

ls -1 "$tmpdir" | while read line
do
  echo "$tmpdata" | grep "$line" > /dev/null || echo "$line $now" >> "$datafile"
done