PERL script to migrate / rename files

Script to look in dir & get album name & create dir of album name then migrate files into dir & rename them Required File Name: ARTIST_-_ALBUM_-_TRACKNUM_-_TITLE.mp3

#!/usr/bin/perl
use Getopt::Long;
use File::Copy;
my $artist;
my $dir = "/mnt/music/sorted";
$result = GetOptions("artist=s" => $artist);
$dir = $dir . "/" . $artist;
opendir(my $dh, $dir) or die "Can't open $dir: $!";

if(!($artist)){
print ("ERROR!!! Must define artistn");
exit(1);
}
my @files = sort grep { -f "$dir/$_" } readdir($dh);
foreach(@files)
{
   if($_ =~ /$artist_-_(.*)?_-_(d*)_-_(.*).mp3/)
   {
      $_ =~ /$artist_-_(.*)?_-_(d*)_-_(.*).mp3/;
      my $album = $1;
      my $tracknum = $2;
      my $title = $3;
      #print $album . " - " . $tracknum . " - " . $title . "n";
      #print ($_ . "n");
      my $albumdir = $dir . "/" . $album;
      if(! -d $albumdir)
      {
         mkdir $albumdir;
      }
      my $new_file_name = $tracknum . "_-_" . $title . ".mp3";
      #print("mv $dir/$_ $albumdir/$new_file_namen");
      move("$dir/$_", "$albumdir/$new_file_name");
      #chdir($albumdir);
      #my $cmd = "rename -n s/^" . $artist . "_-_" . $album . "_-_// *";
      #print(`$cmd` . "n");
      #print($cmd . "n");
      #chdir($dir);
   }
   else
   {
      print($_ . " DOES NOT MATCHn");
   }
}

MySQL – Create User

mysql> create database dbname; 
Query OK, 1 row affected (0.02 sec) 

mysql> grant all privileges on dbname.* to 'username'@'%' identified by 'password'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> grant all privileges on dbname.* to 'username'@'localhost' identified by 'password'; 
Query OK, 0 rows affected (0.00 sec)

MySQL – Clone DB

 mysqladmin create <new_db_name> -u <user> --password=<password> && mysqldump -u <user> --password=<password> <db_name> | mysql -u <user> --password=<password> -h localhost <new_db_name>

Maven AntRun + Release Plugin == argument problems

Scenario: The company had multiple mobile applications (Android, iOS, BB, PalmOS) with build scripts written in ANT.

I wanted to utilize MVN for the sake of dependency management, package repository, release versioning, and automatic branching / tagging of SVN. Therefore, I wrapped MVN around ANT via AntRun plugin and implemented the Release Plugin.

We hit a snag when MVN was calling ANT. How do I pass the args to MVN and onto ANT? Solution: -Darguments

mvn release:clean release:prepare -Darguments=-Dplatform=iPhone -Dprovisioning_profile=some_profile -Denv=test

The pom.xml looks like:

...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration />
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<target>
<property name="env" value="${env}" />
<property name="provisioning_profile" value="${provisioning_profile}" />
<property name="platform" value="${platform}" />
<ant antfile="./src/build.xml" target="clean" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<target>
<property name="env" value="${env}" />
<property name="provisioning_profile" value="${provisioning_profile}" />
<property name="platform" value="${platform}" />
<ant antfile="./src/build.xml" target="checkout_build_ftp" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...

Maven release plugin local modifications

You are trying to do a release

cmuser@cmlin01:~$ mvn release:prepare -DreleaseVersion=1.0.0.RC1 -DdryRun=true

And you see an error like:

...
[INFO] [INFO] Working directory: C:workspacesHelloWorldbranchesHelloWorld-1_0component1
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Cannot create the build number because you have local modifications :
[INFO] [pom.xml.releaseBackup:unknown]
[INFO] [pom.xml.tag:unknown]
[INFO] [release.properties:unknown]
...

To fix, you need to have SVN ignoring those files.

cmuser@cmlin01:~$ vi /home/cmuser/.subversion/config 
...
global-ignores = pom.xml.* release.properties
...

Now run it again.

mvn release:prepare -DreleaseVersion=1.0.0.RC1 -DdryRun=true