Software RAID type perl script

So I have had a problem whereby I have 1.2TB of hard drive space on my server split across 5 drives. I am constantly going to the movies folder in this drive, then the movies folder in that drive, trying to check that I didn’t accidentally leave any pornos lying around.

So I made a script to display multiple folders of the same name accross drives in their own folder under /home/shared.

So I made a folder called shared in my /home directory and in it created longhand names of categories like so:

[hamstar@dolmayan ~]# ls -l /home/shared
total 132
-rwxrwxrwx   1 root root     6 2009-06-21 05:25 1.2TB.in.total.txt
drwxr-xr-x   2 root root 49152 2009-06-21 05:21 Albumart
drwxr-xr-x   4 root root  4096 2009-06-21 05:21 Anime
drwxr-xr-x  26 root root  4096 2009-06-25 10:07 Applications
drwxr-xr-x  14 root root  4096 2009-06-21 05:21 Audiobooks
drwxr-xr-x  11 root root  4096 2009-06-21 05:20 Cartoons
drwxr-xr-x   5 root root  4096 2009-06-21 05:21 Comedy
drwxr-xr-x  18 root root  4096 2009-06-21 05:20 Documentaries
drwxr-xr-x  11 root root  4096 2009-06-21 05:21 Games
drwxr-xr-x   8 root root  4096 2009-06-21 05:20 Guides
drwxr-xr-x  91 root root 20480 2009-06-25 09:06 Movies
drwxr-xr-x  13 root root  4096 2009-06-21 05:21 Music
drwxr-xr-x 141 root root  4096 2009-06-25 14:05 Music (Unsorted)
drwxr-xr-x   2 root root  4096 2009-06-21 05:21 Music Videos
drwxr-xr-x  42 root root  4096 2009-06-21 05:20 Pictures
drwxr-xr-x   5 root root  4096 2009-06-21 05:20 Pr0n
drwxr-xr-x  28 root root  4096 2009-06-21 05:21 TV
drwxr-xr-x  15 root root  4096 2009-06-21 05:21 Videos

Then in each drive under the /mnt/ folder I created specifically named shorthand folders for my stuff like so:

[hamstar@dolmayan ~]# ls -l /mnt/sde1/
total 196
drwxrwxrwx   2 hamstar hamstar 53248 2009-06-01 14:06 albumart
drwxrwxrwx   9 hamstar hamstar  4096 2009-06-11 08:44 apps
drwxrwxrwx  12 hamstar hamstar  4096 2009-05-25 01:24 audiobooks
drwxrwxrwx   5 hamstar hamstar  4096 2009-05-22 13:29 comedy
drwxrwxrwx   5 hamstar hamstar  4096 2009-05-24 15:30 docos
drwxrwxrwx   6 hamstar hamstar  4096 2009-05-24 16:03 games
drwxrwxrwx   3 pcguest pcguest  4096 2009-05-24 15:53 guides
drwx------   2 root    root    16384 2009-05-19 07:59 lost+found
drwxrwxrwx  91 hamstar hamstar 20480 2009-06-25 08:46 movies
-rwxrwxrwx   1 hamstar hamstar  7411 2009-05-19 12:35 movies2.txt
drwxrwxrwx  13 hamstar hamstar  4096 2009-05-24 13:52 music
drwxrwxrwx 142 hamstar hamstar  4096 2009-06-01 14:29 music-unsorted
drwxrwxrwx   2 hamstar hamstar  4096 2009-05-25 15:48 music-videos
drwxrwxrwx   2 pcguest pcguest  4096 2009-06-25 14:27 Private Folder
drwxrwxrwx   3 pcguest pcguest  4096 2009-05-24 16:06 tv
drwxrwxrwx   9 hamstar hamstar  4096 2009-05-24 09:52 videos

And then I put this perl script in the /etc/cron.hourly folder and it updates the /home/shared folder with symbolic links to all the (specified) folders on all the drives.

#!/usr/bin/perl

use strict;
use warnings;

my $command;
my $base_dir = '/home/shared/';

my @search_dirs = (
        '/mnt/sda3',
        '/mnt/sdb1',
        '/mnt/sdc1',
        '/mnt/sdd1',
        '/mnt/sde1'
);

my %folders = (
        'Music' => 'music',
        'TV' => 'tv',
        'Applications' => 'apps',
        'Comedy' => 'comedy',
        'Documentaries' => 'docos',
        'Games' => 'games',
        'Movies' => 'movies',
        'Music\ Videos' => 'music-videos',
        'Music\ \(Unsorted\)' => 'music-unsorted',
        'Guides' => 'guides',
        'Audiobooks' => 'audiobooks',
        'Albumart' => 'albumart',
        'Videos' => 'videos',
        'Cartoons' => 'cartoons',
        'Pictures' => 'pics',
        'Anime' => 'anime',
        'Pr0n' => 'pr0n'
);

foreach my $dir (@search_dirs) {
        foreach my $share (keys %folders) {
                $command = "cp -Rs $dir/$folders{$share}/* $base_dir$share/ > /dev/null 2>&1";

                qx/$command/;
        }
}

chdir($base_dir);
$command = "cleanlinks > /dev/null 2>&1";
qx/$command/;

exit 0;

It even automatically creates folders under folders so the docos from docos/Bad Government on one drive are in the same folder as the docos from docos/Bad Government on another drive.

Then I can share the /home/shared folder without worry of my “Private Folder” or any folder not specified in the script being seen by people browsing the network or at lans or whatever.

Sure its a little quick and nasty, just throws any errors straight into the bit bucket, but its works pretty sweet.

All thanks to cp -Rs :)

P.S. All my shares data is paid for and legit.

Tags: , , ,

Leave a Reply