0: This is wackyass, a webcam archiving system. No, it's not
1: commented, and no there's no POD. This was a little
2: project I did at home to archive single frame pics on a 24
3: hour rotation.
4:
5: use FileHandle;
6: use LWP::Simple;
7:
8: if ($ARGV[0] eq 'stop')
9: { $kill = 1; }
10: if (-e 'pidfile')
11: { $running = 1; }
12: if ($kill and $running)
13: {
14: $pfh = new FileHandle 'pidfile', O_RDONLY;
15: chomp($pid = $pfh->getline);
16: chomp($stime = $pfh->getline);
17: undef $pfh;
18: $skill = kill 9, $pid;
19: $srm = unlink 'pidfile';
20: if ($skill and $srm)
21: {
22: ($sec, $min, $hour, $mday, $mon, $year,
23: $wday, $yday, $isdst) = localtime();
24: $etime = '0' x (2 - length($hour)).$hour.':'.'0' x (2 - length($min)).$min.':'.'0' x (2 - length($sec)).$sec.' '.'0' x (2 - length($mon + 1)).($mon + 1).'/'.'0' x (2 - length($mday)).$mday.'/'.($year + 1900);
25: $lfh = new FileHandle '../log/logfile', O_CREAT|O_APPEND;
26: print $lfh "wackyass:$pid start time: $stime\n";
27: print $lfh "wackyass:$pid end time: $etime\n";
28: undef $lfh;
29: }
30: elsif ($skill)
31: { print "\nUnable to remove the pidfile.\n"; }
32: elsif ($srm)
33: { print "\nUnable to kill $pid.\n"; }
34: exit(0);
35: }
36: elsif ($kill)
37: {
38: print "\nWackyass is not currently running.\n";
39: exit(0);
40: }
41: elsif ($running)
42: {
43: print "\nWackyass is currently running.\n";
44: exit(0);
45: }
46:
47: ($sec, $min, $hour, $mday, $mon, $year,
48: $wday, $yday, $isdst) = localtime();
49: $stime = '0' x (2 - length($hour)).$hour.':'.'0' x (2 - length($min)).$min.':'.'0' x (2 - length($sec)).$sec.' '.'0' x (2 - length($mon + 1)).($mon + 1).'/'.'0' x (2 - length($mday)).$mday.'/'.($year + 1900);
50: $ppid = $$;
51: $pfh = new FileHandle 'pidfile', O_CREAT|O_WRONLY;
52: print $pfh "$$\n$stime\n";
53: undef $pfh;
54:
55: if ($pid = fork)
56: {
57: $lmin = -1;
58: $i = 0;
59: for (;;)
60: {
61: ($sec, $min, $hour, $mday, $mon, $year,
62: $wday, $yday, $isdst) = localtime();
63: $ssec = $sec;
64: if ($lmin != $min)
65: {
66: $i = 0;
67: $lmin = $min;
68: }
69: if ($sec > 50)
70: {
71: $i = 0;
72: $min++;
73: $lmin = $min;
74: }
75: if ($i > 5)
76: { $i = 0; }
77: if ($min == 60)
78: {
79: $min = 0;
80: $lmin = $min;
81: $hour++;
82: }
83: if ($hour == 24)
84: { $hour = 0; }
85: $filename = '/usr/local/apache/sites/wackyass/htdocs/'.'0' x (2 - length($hour)).$hour.'/'.'0' x (2 - length($min)).$min.$i.'.jpg';
86: $ifh = new FileHandle "$filename", O_CREAT|O_WRONLY;
87: ($sec, $min, $hour, $mday, $mon, $year,
88: $wday, $yday, $isdst) = localtime();
89: if ($sec < $ssec)
90: { $sec += 60; }
91: $stime = 10 - ($sec - $ssec);
92: sleep $stime;
93: print $ifh get("http://192.168.0.108:8080");
94: undef $ifh;
95: $i++;
96: }
97: }
98: elsif (defined $pid)
99: {
100: for (;;)
101: {
102: ($sec, $min, $hour, $mday, $mon, $year,
103: $wday, $yday, $isdst) = localtime();
104: $min++;
105: if ($min == 60)
106: {
107: $hour++;
108: if ($hour == 24)
109: { $hour = 0; }
110: $min = 0;
111: }
112: for ($i = 0; $i < 6; $i++)
113: {
114: $filename = '/usr/local/apache/sites/wackyass/htdocs/'.'0' x (2 - length($hour)).$hour.'/'.'0' x (2 - length($min)).$min.$i.'.jpg';
115: if ((-M $filename) >= 0.5)
116: { unlink $filename; }
117: }
118: if ($ppid != getppid)
119: { kill 9, $$; }
120: sleep 60;
121: }
122: }
In reply to Wackyass by PsychoSpunk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |