From 4a643e3ce0789341e5f4a12f30421d9140c18ce8 Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 24 May 2011 15:06:35 +0000 Subject: [PATCH] Added --run-check flag to audio processing steps 2-4 scripts to check for concurrency git-svn-id: svn://192.168.202.10@1662 3d104415-ff17-0410-8863-d5cf3c621b8a --- .../trunk/bin/AST_CRON_audio_2_compress.pl | 25 ++++++++++++++-- agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl | 23 ++++++++++++++- agc_2-X/trunk/bin/AST_CRON_audio_3_newftp.pl | 29 +++++++++++++++++-- agc_2-X/trunk/bin/AST_CRON_audio_4_ftp2.pl | 23 ++++++++++++++- 4 files changed, 94 insertions(+), 6 deletions(-) diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl b/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl index 4cea20ac..1b899cb7 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl @@ -26,13 +26,14 @@ # # This program assumes that recordings are saved by Asterisk as .wav # -# Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # # 80302-1958 - First Build # 80731-2253 - Changed size comparisons for more efficiency # 90727-1417 - Added GSW format option # 101207-1024 - Change to GSW option because of SoX flag changes in 14.3.0 +# 110524-1059 - Added run-check concurrency check option # $GSM=0; $MP3=0; $OGG=0; $GSW=0; @@ -57,7 +58,8 @@ if (length($ARGV[0])>1) print " [--GSM] = compress into GSM codec\n"; print " [--MP3] = compress into MPEG-Layer-3 codec\n"; print " [--OGG] = compress into OGG Vorbis codec\n"; - print " [--GSW] = compress into GSM codec with RIFF headers and .wav extension\n\n"; + print " [--GSW] = compress into GSM codec with RIFF headers and .wav extension\n"; + print " [--run-check] = concurrency check, die if another instance is running\n\n"; exit; } else @@ -77,6 +79,11 @@ if (length($ARGV[0])>1) $T=1; $TEST=1; print "\n-----TESTING -----\n\n"; } + if ($args =~ /--run-check/i) + { + $run_check=1; + if ($DB) {print "\n----- CONCURRENCY CHECK -----\n\n";} + } if ($args =~ /--GSM/i) { $GSM=1; @@ -167,6 +174,20 @@ foreach(@conf) $i++; } +### concurrency check +if ($run_check > 0) + { + my $grepout = `/bin/ps ax | grep $0 | grep -v grep`; + my $grepnum=0; + $grepnum++ while ($grepout =~ m/\n/g); + if ($grepnum > 1) + { + if ($DB) {print "I am not alone! Another $0 is running! Exiting...\n";} + exit; + } + } + + # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl b/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl index d5291f67..dfd575cc 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl @@ -32,7 +32,7 @@ # # This program assumes that recordings are saved by Asterisk as .wav # -# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # # 80302-1958 - First Build @@ -44,6 +44,7 @@ # 90818-1017 - Added a transfer limit and list limit options. # 90827-2013 - Fixed list limit option # 91123-0037 - Added FTP CLI options +# 110524-1049 - Added run-check concurrency check option # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @@ -95,6 +96,7 @@ if (length($ARGV[0])>1) print " [--WAV] = copy WAV files\n"; print " [--GSW] = copy GSM with RIFF headers and .wav extension files\n"; print " [--nodatedir] = do not put into dated directories\n"; + print " [--run-check] = concurrency check, die if another instance is running\n"; print " [--ftp-server=XXX] = FTP server\n"; print " [--ftp-login=XXX] = FTP server login account\n"; print " [--ftp-pass=XXX] = FTP server password\n"; @@ -123,6 +125,11 @@ if (length($ARGV[0])>1) $NODATEDIR=1; if ($DB) {print "\n----- NO DATE DIRECTORIES -----\n\n";} } + if ($args =~ /--run-check/i) + { + $run_check=1; + if ($DB) {print "\n----- CONCURRENCY CHECK -----\n\n";} + } if ($args =~ /--transfer-limit=/i) { my @data_in = split(/--transfer-limit=/,$args); @@ -271,6 +278,20 @@ foreach(@conf) $i++; } +### concurrency check +if ($run_check > 0) + { + my $grepout = `/bin/ps ax | grep $0 | grep -v grep`; + my $grepnum=0; + $grepnum++ while ($grepout =~ m/\n/g); + if ($grepnum > 1) + { + if ($DB) {print "I am not alone! Another $0 is running! Exiting...\n";} + exit; + } + } + + # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_3_newftp.pl b/agc_2-X/trunk/bin/AST_CRON_audio_3_newftp.pl index 6ee2612f..f239a61f 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_3_newftp.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_3_newftp.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# AST_CRON_audio_3_newftp.pl version 2.2.0 +# AST_CRON_audio_3_newftp.pl version 2.4 # # This is a STEP-3 program in the audio archival process. Normally you can run it # every 3 minutes and copies the recording files to an FTP server. @@ -52,10 +52,12 @@ # --ftp-host="10.10.10.15" --ftp-port=21 --ftp-user="username" --ftp-pass="password" --ftp-dir="RECORDINGS" \ # --url-path="http://10.10.10.15/RECORDINGS" --transfer-limit=50 --list-limit=200 --campaign_id="TESTCAMP1-TESTCAMP2" # -# Copyright (C) 2008 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # CHANGELOG: # 90930-1405 - mikec - first build +# 110524-1054 - Added run-check concurrency check option +# use 5.008; use strict; @@ -72,6 +74,7 @@ use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sle my $debug = 0; my $debugX = 0; my $test = 0; +my $run_check = 0; my $pingtype = "tcp"; my $pingtimeout = 5; @@ -192,6 +195,7 @@ if (length($ARGV[0])>1) { print " [--transfer-limit=XXX] = the number of files to transfer before giving up. Default is 1000\n"; print " [--list-limit=XXX] = number of files to list in the directory before moving on\n"; print " [--no-date-dir] = does not put the files in a dated directory.\n"; + print " [--run-check] = concurrency check, die if another instance is running\n"; print " [--campaign_id] = which OUTBOUND campaigns to transfer files for in a '-' delimited list \n"; print " (this only works for outbound calls, not inbound or transfers)\n"; print " [--ingroup_id] = which ingroups to transfer files for in a '-' delimited list\n"; @@ -217,6 +221,12 @@ if (length($ARGV[0])>1) { print "\n----- NO DATE DIRECTORIES -----\n\n"; } } + if ($args =~ /--run-check/i) + { + $run_check=1; + if ($debug) {print "\n----- CONCURRENCY CHECK -----\n\n";} + } + if ($args =~ /--ping-type=/i) { my @data_in = split(/--ping-type=/,$args); $pingtype = $data_in[1]; @@ -369,6 +379,21 @@ if ($ingrp_check) { @ingrp_array = split(/-/,$ingroups); } + +### concurrency check +if ($run_check > 0) + { + my $grepout = `/bin/ps ax | grep $0 | grep -v grep`; + my $grepnum=0; + $grepnum++ while ($grepout =~ m/\n/g); + if ($grepnum > 1) + { + if ($debug) {print "I am not alone! Another $0 is running! Exiting...\n";} + exit; + } + } + + #### connect to the db #### my $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_4_ftp2.pl b/agc_2-X/trunk/bin/AST_CRON_audio_4_ftp2.pl index cec4e7c7..2693d40d 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_4_ftp2.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_4_ftp2.pl @@ -26,10 +26,11 @@ # # This program assumes that recordings are saved by Asterisk as .wav # -# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # # 91123-0005 - First Build +# 110524-1052 - Added run-check concurrency check option # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @@ -71,6 +72,7 @@ if (length($ARGV[0])>1) print " [--help] = this screen\n"; print " [--debug] = debug\n"; print " [--debugX] = super debug\n"; + print " [--run-check] = concurrency check, die if another instance is running\n"; print " [--transfer-limit=XXX] = number of files to transfer before exiting\n"; print " [--list-limit=XXX] = number of files to list in the directory before moving on\n"; print " [--ftp-server=XXX] = FTP server\n"; @@ -104,6 +106,11 @@ if (length($ARGV[0])>1) $NODATEDIR=1; if ($DB) {print "\n----- NO DATE DIRECTORIES -----\n\n";} } + if ($args =~ /--run-check/i) + { + $run_check=1; + if ($DB) {print "\n----- CONCURRENCY CHECK -----\n\n";} + } if ($args =~ /--transfer-limit=/i) { my @data_in = split(/--transfer-limit=/,$args); @@ -215,6 +222,20 @@ foreach(@conf) $i++; } + +### concurrency check +if ($run_check > 0) + { + my $grepout = `/bin/ps ax | grep $0 | grep -v grep`; + my $grepnum=0; + $grepnum++ while ($grepout =~ m/\n/g); + if ($grepnum > 1) + { + if ($DB) {print "I am not alone! Another $0 is running! Exiting...\n";} + exit; + } + } + # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';}