Jump to content

PHP Shell Script


bschultz

Recommended Posts

I've written some code to move a bunch of mp3's from one folder on a network server, rename them...based on the day of the week and date of the month...and then put them on another folder on the original server.

 

Here's the code

 

#!/usr/bin/php
<?php
$today = date('m.d.y');
$week = date('W');
$weekplus = $week + 1;
$daynumber = date('w');
//$dayofweek = date('D');


if (date('D') == "Mon") { $dayofweek = "mon"; }
elseif (date('D') == "Tue") { $dayofweek = "tue"; }
elseif (date('D') == "Wed") { $dayofweek = "wed"; }
elseif (date('D') == "Thu") { $dayofweek = "thu"; }
elseif (date('D') == "Fri") { $dayofweek = "fri"; }


//original filenames are in this format  10361MRS-H01T01.mp3

$file1 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T01.mp3";
$file2 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T02.mp3";
$file3 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T03.mp3";
$file4 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S01.mp3";
$file5 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S02.mp3";
$file6 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S03.mp3";

$file7 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T01.mp3";
$file8 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T02.mp3";
$file9 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T03.mp3";
$file10 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S01.mp3";
$file11 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S02.mp3";
$file12 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S03.mp3";

$file13 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T01.mp3";
$file14 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T02.mp3";
$file15 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T03.mp3";
$file16 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S01.mp3";
$file17 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S02.mp3";
$file18 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S03.mp3";

$file19 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T01.mp3";
$file20 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T02.mp3";
$file21 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T03.mp3";
$file22 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S01.mp3";
$file23 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S02.mp3";
$file24 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S03.mp3";


$deletepath = "/var/www/showdownloads/mrshow/";

exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file1' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file2' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file3' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file4' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file5' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file6' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file7' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file8' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file9' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file10' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file11' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file12' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file13' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file14' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file15' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file16' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file17' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file18' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file19' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file20' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file21' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file22' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file23' /var/www/showdownloads/mrshow/");
exec("scp '[email protected]:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file24' /var/www/showdownloads/mrshow/");

rename("$deletepath/$file1", "$deletepath/mr_$dayofweek-2-1.mp3");
rename("$deletepath/$file2", "$deletepath/mr_$dayofweek-2-3.mp3");
rename("$deletepath/$file3", "$deletepath/mr_$dayofweek-2-5.mp3");
rename("$deletepath/$file4", "$deletepath/mr_$dayofweek-2-2.mp3");
rename("$deletepath/$file5", "$deletepath/mr_$dayofweek-2-4.mp3");
rename("$deletepath/$file6", "$deletepath/mr_$dayofweek-2-6.mp3");
rename("$deletepath/$file7", "$deletepath/mr_$dayofweek-3-1.mp3");
rename("$deletepath/$file8", "$deletepath/mr_$dayofweek-3-3.mp3");
rename("$deletepath/$file9", "$deletepath/mr_$dayofweek-3-5.mp3");
rename("$deletepath/$file10", "$deletepath/mr_$dayofweek-3-2.mp3");
rename("$deletepath/$file11", "$deletepath/mr_$dayofweek-3-4.mp3");
rename("$deletepath/$file12", "$deletepath/mr_$dayofweek-3-6.mp3");
rename("$deletepath/$file13", "$deletepath/mr_$dayofweek-4-1.mp3");
rename("$deletepath/$file14", "$deletepath/mr_$dayofweek-4-3.mp3");
rename("$deletepath/$file15", "$deletepath/mr_$dayofweek-4-5.mp3");
rename("$deletepath/$file16", "$deletepath/mr_$dayofweek-4-2.mp3");
rename("$deletepath/$file17", "$deletepath/mr_$dayofweek-4-4.mp3");
rename("$deletepath/$file18", "$deletepath/mr_$dayofweek-4-6.mp3");
rename("$deletepath/$file19", "$deletepath/mr_$dayofweek-5-1.mp3");
rename("$deletepath/$file20", "$deletepath/mr_$dayofweek-5-3.mp3");
rename("$deletepath/$file21", "$deletepath/mr_$dayofweek-5-5.mp3");
rename("$deletepath/$file22", "$deletepath/mr_$dayofweek-5-2.mp3");
rename("$deletepath/$file23", "$deletepath/mr_$dayofweek-5-4.mp3");
rename("$deletepath/$file24", "$deletepath/mr_$dayofweek-5-6.mp3");

exec("scp '/$deletepath/mr_$dayofweek-2-1.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-1.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-2-2.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-2.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-2-3.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-3.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-2-4.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-4.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-2-5.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-5.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-2-6.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-6.mp3'");

exec("scp '/$deletepath/mr_$dayofweek-3-1.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-1.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-3-2.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-2.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-3-3.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-3.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-3-4.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-4.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-3-5.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-5.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-3-6.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-6.mp3'");

exec("scp '/$deletepath/mr_$dayofweek-4-1.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-1.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-4-2.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-2.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-4-3.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-3.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-4-4.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-4.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-4-5.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-5.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-4-6.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-6.mp3'");

exec("scp '/$deletepath/mr_$dayofweek-5-1.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-1.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-5-2.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-2.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-5-3.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-3.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-5-4.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-4.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-5-5.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-5.mp3'");
exec("scp '/$deletepath/mr_$dayofweek-5-6.mp3' '[email protected]:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-6.mp3'");

?>

 

The problem is, this is the only way I can get this to work.  I actually want to name the files in this format

 

mr_mon_2-1.mp3

 

Instead of the format now

mr_mon-2-1.mp3

 

The difference being that after the three letter version of the date, I have to have a dash...I want an underscore there.

 

If I try to rename the file to use an underscore...it doesn't use the day of the week...so it turns out to be mr_2-1.mp3

 

Any ideas what I'm doing wrong?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/213323-php-shell-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.