Annotation of wpscripts/zlist/zlist, Revision 1.9
1.1 yason 1: #!/usr/bin/perl
1.9 ! yason 2: # $Id: zlist,v 1.8 2011/12/21 09:33:05 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:
1.8 yason 82: # fetch probas
83: db_fetch(1);
1.1 yason 84:
1.8 yason 85: #print "****** probas ($#numcard) ******\n";
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: }
1.8 yason 94: print "\n";
95:
96: # fetch TT
97: db_fetch(2);
98:
99: print BOLD WHITE ON_BLUE "TT queue". RESET . " ($#numcard pcs.) :\n";
100: $i = 0;
101: while( ($numcard[$i]) )
102: {
103: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
104: $i++;
105: $total++;
106: }
107: print "\n";
108:
1.9 ! yason 109: # fetch zayavki_
1.8 yason 110: db_fetch(3);
111:
1.9 ! yason 112: print BOLD WHITE ON_BLUE "zayavki_ queue". RESET . " ($#numcard pcs.) :\n";
! 113: $i = 0;
! 114: while( ($numcard[$i]) )
! 115: {
! 116: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
! 117: $i++;
! 118: $total++;
! 119: }
! 120: print "\n";
! 121:
! 122: # fetch proba_
! 123: db_fetch(4);
! 124:
! 125: print BOLD WHITE ON_BLUE "proba_ queue". RESET . " ($#numcard pcs.) :\n";
1.8 yason 126: $i = 0;
127: while( ($numcard[$i]) )
128: {
129: print "$numcard[$i]\t[ executed $time[$i], priority=$pri[$i], file=$path[$i] (size=$size[$i]) ]\n";
130: $i++;
131: $total++;
132: }
133: print "\n";
1.1 yason 134:
135:
136: # print summary information
1.7 yason 137: print BOLD WHITE . "Total: " . RESET . "$total files in queue.\n";
1.1 yason 138:
139: # close connection
140: db_disconnect();
141:
142:
143: ### database functions
144:
145: sub db_connect()
146: {
147: $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
148: }
149:
150:
151: sub db_select()
152: {
1.2 yason 153: $dbh->do("use full_print");
1.1 yason 154: }
155:
156:
157: sub db_fetch($)
158: {
159: my $type_file = shift;
160: my $i = 0;
161: my $searchpath;
162:
1.2 yason 163: $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 164: $sth->execute( ) or die "unable to execute query $query error $DBI::errstr";
165:
166: # zero elements
167: $#numcard = $#path = $#time = $#pri = $#tx_count = 0;
168:
169: while( ($numcard[$i], $path[$i], $time[$i], $pri[$i], $tx_count[$i]) = $sth->fetchrow_array())
170: {
171: # truncate spaces
172: do
173: {
174: chop($path[$i]);
175: }
176: while( index($path[$i], ' ', 0) != -1 );
177:
1.3 yason 178: # remove first 13 symbols in SMB path (\\fileserver\)
179: $searchpath = substr($path[$i], 13);
1.1 yason 180:
181: # hardcoded
1.6 yason 182: # remove first symbols to get only filename (i.e. \\fileserver\zayavki\ - 21 symbols)
183: $path[$i] = substr($path[$i], 21) if ($type_file == 0); #zayavki
184: $path[$i] = substr($path[$i], 19) if ($type_file == 1); #proba
1.8 yason 185: $path[$i] = substr($path[$i], 16) if ($type_file == 2); #TT
1.9 ! yason 186: $path[$i] = substr($path[$i], 22) if ($type_file == 3); #zayavki_
! 187: $path[$i] = substr($path[$i], 19) if ($type_file == 4); #proba_
1.1 yason 188:
189: # make local file path
1.3 yason 190: $searchpath =~ tr/\\/\//;
1.4 yason 191: $searchpath = '/mnt/maket/' . $searchpath;
1.3 yason 192:
193:
1.1 yason 194: # finally, get file size
195: $size[$i] = -s $searchpath;
196: $size[$i] = ($size[$i] > 1048576 ? int($size[$i] / 1024 / 1024) . " MB" : int($size[$i] / 1024) . " KB");
197:
198: # this should work fine
1.7 yason 199: $size[$i] = WHITE ON_RED . "File not found" . RESET if (! -e $searchpath);
1.1 yason 200: $i++;
201: }
202:
203: $sth->finish();
204:
205: }
206:
207:
208: sub db_disconnect()
209: {
210: $dbh->disconnect();
211: }
CVSweb