Annotation of openbsd/OpenBSDTorrents/NewTorrents.pl, Revision 1.3
1.1 andrew 1: #!/usr/bin/perl -T
1.3 ! andrew 2: #$Id: NewTorrents.pl,v 1.2 2005/03/24 05:32:49 andrew Exp andrew $
1.1 andrew 3: use strict;
4: use warnings;
5: use diagnostics;
6:
7: use lib 'lib';
8: use OpenBSDTorrents;
9:
1.3 ! andrew 10: use POSIX 'setsid';
! 11:
1.1 andrew 12: %ENV = ();
13:
14: use YAML;
15:
1.3 ! andrew 16: # *** This requires --log-format="%t [%p] %o %f %l" on the rsync command
! 17:
1.1 andrew 18: my $last_dir = '';
19: while (<>) {
20: chomp;
21: if (my ($year, $mon, $mday, $time, $pid, $oper, $file, $size) =
22: m#^(\d{4})/(\d{2})/(\d{2}) (\d{2}:\d{2}:\d{2}) \[(\d+)\] (\S+) (.+) (\d+)$# ) {
23: #print "($year, $mon, $mday, $time, $pid, $oper, $file, $size)\n";
24: my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#;
25: #print "$dir - $file\n";
26: if ($last_dir && $last_dir ne $dir) {
1.2 andrew 27: StartTorrent($last_dir);
1.1 andrew 28: }
29: $last_dir = $dir;
30: } else {
31: #print $_;
32: }
1.2 andrew 33: }
34: StartTorrent($last_dir);
35:
1.3 ! andrew 36: sleep(90);
! 37:
! 38: StartTorrent('skip');
! 39:
! 40:
1.2 andrew 41: sub StartTorrent
42: {
43: my $dir = shift;
1.3 ! andrew 44: return undef unless $dir;
1.2 andrew 45:
1.3 ! andrew 46: if ($dir ne 'skip') {
! 47: $dir = "$BaseName/$dir";
! 48: }
! 49:
1.2 andrew 50: # This actually needs to be a sub that forks off
51: # the generation of this, and the running of the update script.
52: print "MakeTorrents.pl $BaseName/$dir\n";
1.3 ! andrew 53:
! 54: defined(my $pid = fork) or die "Can't fork: $!";
! 55:
! 56: return if $pid;
! 57:
! 58: chdir $HomeDir or die "Can't chdir to $HomeDir: $!";
! 59:
! 60: setsid or die "Can't start a new session: $!";
! 61: #open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
! 62: #open STDOUT, '>/dev/null'
! 63: # or die "Can't write /dev/null: $!";
! 64: #open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
! 65:
! 66: exec('/home/andrew/OpenBSDTorrents/regen.sh', "$dir");
1.1 andrew 67: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>