Annotation of wpscripts/zlist/zlist, Revision 1.7
1.1 yason 1: #!/usr/bin/perl
1.7 ! yason 2: # $Id: zlist,v 1.6 2011/07/25 14:28:51 yason Exp $
1.1 yason 3: use DBI;
4: use Term::ANSIColor qw(:constants);
5: use Time::HiRes qw(gettimeofday tv_interval);
6:
7: $| = 1;
8:
9: # database
1.2 yason 10: our $server = "pdc";
11: our $user = "sa";
12: our $pass = "aekghbynflvby";
1.1 yason 13: our $dsn = "DBI:Sybase:server=$server";
14: our $sth;
15:
16: # response handlers
17: our @numcard;
18: our @time;
19: our @pri;
20: our @path;
21: our @size;
22: our @tx_count;
23:
24: my $i; # counter
25: my $total = 0; # total files
26:
27: ###
28: my $time1 = [gettimeofday];
29:
30: # connect to database server
31: db_connect();
32:
33: # select database
34: db_select();
35:
36: # fetch zayavki
37: db_fetch(0);
38:
39: my $time2 = [gettimeofday];
40:
1.7 ! yason 41: print GREEN "DB response time: " . tv_interval($time1, $time2) . " seconds\n". RESET;
1.1 yason 42:
43: if( ! -e "/var/run/ztransfer.lock")
44: {
1.7 ! yason 45: print YELLOW "ztransfer is not running\n" . RESET;
1.1 yason 46: }
47: else
48: {
1.2 yason 49: if( -e "/var/log/wpscripts/ztransfer/FILE" && -e "/var/log/ztransfer/ACTION")
1.1 yason 50: {
1.2 yason 51: open(CURRENT, "/var/log/wpscripts/ztransfer/FILE");
1.1 yason 52: my $file = <CURRENT>;
53: close(CURRENT);
54:
1.2 yason 55: open(CURRENT, "/var/log/wpscripts/ztransfer/ACTION");
1.1 yason 56: my $action = <CURRENT>;
57: close(CURRENT);
58:
59:
60: print "DEBUG: $file $action\n";
61:
1.7 ! yason 62: print YELLOW "ztransfer is running [ " . ($action eq 'rar' ? "compressing " : "copying ") . "$file ]\n" . RESET;
1.1 yason 63: }
64: else
65: {
1.7 ! yason 66: print YELLOW "ztransfer is running\n" . RESET;
1.1 yason 67: }
68: }
69:
70: # print out zayavki info
1.7 ! yason 71: print BOLD WHITE ON_BLUE "Zayavki queue". RESET . " ($#numcard pcs.) :\n";
1.1 yason 72: $i = 0;
73: while( ($numcard[$i]) )
74: {
1.7 ! yason 75: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]), transfer counter=$tx_count[$i] ]\n";
1.1 yason 76: $i++;
77: $total++;
78: }
79: print "\n";
80:
81:
82: # fetch probas
1.6 yason 83: db_fetch(1);
1.1 yason 84:
85: # print "****** probas ($#numcard) ******\n";
1.7 ! yason 86: print BOLD WHITE ON_BLUE "Probas queue". RESET . " ($#numcard pcs.) :\n";
1.1 yason 87: $i = 0;
88: while( ($numcard[$i]) )
89: {
1.7 ! yason 90: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
1.1 yason 91: $i++;
92: $total++;
93: }
94: print "\n";
95:
96:
97: # print summary information
1.7 ! yason 98: print BOLD WHITE . "Total: " . RESET . "$total files in queue.\n";
1.1 yason 99:
100: # close connection
101: db_disconnect();
102:
103:
104: ### database functions
105:
106: sub db_connect()
107: {
108: $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
109: }
110:
111:
112: sub db_select()
113: {
1.2 yason 114: $dbh->do("use full_print");
1.1 yason 115: }
116:
117:
118: sub db_fetch($)
119: {
120: my $type_file = shift;
121: my $i = 0;
122: my $searchpath;
123:
1.2 yason 124: $sth = $dbh->prepare ("SELECT numcard,path,time_file,file_priority,tx_count FROM upload_files WHERE status=0 AND type_file=$type_file") or die "SQL prepare failed\n";
1.1 yason 125: $sth->execute( ) or die "unable to execute query $query error $DBI::errstr";
126:
127: # zero elements
128: $#numcard = $#path = $#time = $#pri = $#tx_count = 0;
129:
130: while( ($numcard[$i], $path[$i], $time[$i], $pri[$i], $tx_count[$i]) = $sth->fetchrow_array())
131: {
132: # truncate spaces
133: do
134: {
135: chop($path[$i]);
136: }
137: while( index($path[$i], ' ', 0) != -1 );
138:
1.3 yason 139: # remove first 13 symbols in SMB path (\\fileserver\)
140: $searchpath = substr($path[$i], 13);
1.1 yason 141:
142: # hardcoded
1.6 yason 143: # remove first symbols to get only filename (i.e. \\fileserver\zayavki\ - 21 symbols)
144: $path[$i] = substr($path[$i], 21) if ($type_file == 0); #zayavki
145: $path[$i] = substr($path[$i], 19) if ($type_file == 1); #proba
1.1 yason 146:
147: # make local file path
1.3 yason 148: $searchpath =~ tr/\\/\//;
1.4 yason 149: $searchpath = '/mnt/maket/' . $searchpath;
1.3 yason 150:
151:
1.1 yason 152: # finally, get file size
153: $size[$i] = -s $searchpath;
154: $size[$i] = ($size[$i] > 1048576 ? int($size[$i] / 1024 / 1024) . " MB" : int($size[$i] / 1024) . " KB");
155:
156: # this should work fine
1.7 ! yason 157: $size[$i] = WHITE ON_RED . "File not found" . RESET if (! -e $searchpath);
1.1 yason 158: $i++;
159: }
160:
161: $sth->finish();
162:
163: }
164:
165:
166: sub db_disconnect()
167: {
168: $dbh->disconnect();
169: }
CVSweb