Skip to content

Instantly share code, notes, and snippets.

@ambiorixg12
Created March 3, 2021 18:32
Show Gist options
  • Select an option

  • Save ambiorixg12/92c4fd1d4402bb8ee351d578faa7832a to your computer and use it in GitHub Desktop.

Select an option

Save ambiorixg12/92c4fd1d4402bb8ee351d578faa7832a to your computer and use it in GitHub Desktop.
vm clean 1
<?php
function clean($var) {
$var=stristr($var, '=');
$var=str_replace ("=" ,"",$var);
$var=trim($var);
return $var;
}
$num=$argv[1];
$vm_box="/var/spool/asterisk/voicemail/default/$num/INBOX";
$dir = "/var/spool/asterisk/voicemail/default/$num/INBOX/";
// Open a known directory, and proceed to read its contents
$arr=array();
$arr2=array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
// echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
if (preg_match("/\btxt\b/i", $file, $match)){
file("$vm_box");
$arr[]=$file;
}
}
closedir($dh);
}
}
foreach($arr as $key=> $value){
$file=file($dir.$value);
$arr2[$value]=$file[17];
}
foreach($arr2 as $key=> $value){
if(clean($value)<15){
echo shell_exec("rm $vm_box/$key");
$key=str_replace ("txt" ,"wav",$key);
echo "$vm_box/$key duration : ".clean($value)."\n";
echo shell_exec("rm $vm_box/$key");
}
}
echo "\n";
//echo "total of VM ".count($arr2);
echo "\n";
?>
/usr/bin/php /root/vm_clean.php 633
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment