OptCam.pl
上传用户:qdrechuli
上传日期:2022-08-01
资源大小:917k
文件大小:2k
- #!/usr/bin/perl -w
- use strict;
- use DBI;
- use vars qw(%base);
- sub main
- {
- my $db = DBI->connect("DBI:mysql:netcam","root","");
- my $sqlreq = "SELECT C_ID FROM cam";
- my $sql = $db->prepare($sqlreq);
- $sql->execute();
- while ((my $CID) = $sql->fetchrow())
- {
- $SIG{CHLD} = 'IGNORE';
- my $pid = fork;
- if ($pid==0)
- {
- my $db = DBI->connect("DBI:mysql:netcam","root","");
- while (1)
- {
- my $sqlreq = "SELECT R_ID,R_Img FROM record WHERE ";
- $sqlreq .= "R_Opt=0 and R_CAM=".$CID;
- my $sql = $db->prepare($sqlreq);
- $sql->execute();
- while ((my $RID,my $Img) = $sql->fetchrow())
- {
- print $RID,"n";
- print length($Img),"n";
- open(IMAGE,">/opt/NetAdmin/Net-Cam/data/tmp_".$CID.".jpg");
- print IMAGE $Img;
- close(IMAGE);
- my @args = ("/opt/NetAdmin/Net-Cam/bin/jdo.o","/opt/NetAdmin/Net-Cam/data/tmp_".$CID.".jpg");
- system(@args);
- open(IMAGE,"/opt/NetAdmin/Net-Cam/data/tmp_".$CID.".jpg");
- read IMAGE,$Img,length($Img)*2;
- close(IMAGE);
- print length($Img),"n";
- $base{update} = $db->prepare("UPDATE record SET R_Size=?,R_Img=?,R_Opt=? WHERE R_ID=?");
- $db->do("LOCK TABLE record LOW_PRIORITY WRITE");
- $base{update}->execute(length($Img),$Img,1,$RID);
- $db->do("UNLOCK TABLE");
- }
- $sql->finish();
- }
- $db->disconnect();
- }
- }
- $sql->finish();
- $db->disconnect();
- }
- main();
- exit(0);