File: logcheck

package info (click to toggle)
dotfile 2.2-1
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 4,596 kB
  • ctags: 456
  • sloc: tcl: 11,732; sh: 965; makefile: 304; csh: 13; ansic: 7
file content (47 lines) | stat: -rw-r--r-- 938 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
#! /usr/bin/tclsh7.6
set file [lindex $argv 0]
set days [lindex $argv 1]
set user [lrange $argv 2 end]
set module [file dirname $argv0]

set now [exec /bin/date +%s]
set match 0

if {![file exists $file]} {
  set FILE [open $file w]
} else {
  set FILE [open $file r]
  set line [gets $FILE]
  if {$days != "once"} {
    set cont 1
    while {![eof $FILE] && $cont} {
      set list [split $line :]
      set sec [lindex $list 0]
      if {[expr ($now-$sec)/(3600*24)] >= $days} {
        set line [gets $FILE]
      } else {
        set cont 0
      }
    }
  }

  set newList ""
  while {![eof $FILE]} {
    append newList $line\n
    if {!$match} {
      set list [split $line :]
      if {[lindex $list 1] == $user} {
        set match 1
      }
    }
    set line [gets $FILE]
  }
  close $FILE
  set FILE [open $file w]
  puts -nonewline $FILE $newList
}
if {!$match} {
  puts $FILE "$now:$user"
  close $FILE
}
exit [expr !$match]