#!/usr/bin/perl

#nicl . -create /mounts/nfsserver:\\/exported\\/path

#nicl . -append /mounts/nfsserver:\\/exported\\/path type nfs
#nicl . -append /mounts/nfsserver:\\/exported\\/path opts ""
#nicl . -append /mounts/nfsserver:\\/exported\\/path dir /private/mnt


# recupero i dati chemi servono da osiris
 system 'ssh -i /var/root/.ssh/valeria_dsa valeria@osiris "stat /home/* | grep File" > mount_stat'; 


#cancello tutti i mount point dal db
system " nicl . -delete /mounts";
$i=0;
#apro il file che contiene i dati ricavati dallo stat di osiris
open (MOUNT_STAT, "< mount_stat") || die "cannot open file mount_stat\n";
while (<MOUNT_STAT>)
{

#per ogni entry ricavo host, mount point e percorso remoto
$entry = $_;
$entry =~s/.*\"(\/.*)\"(?!\/).*\/n\/([^\/]*)(.*)\"$//g;
$mount=$1;
$host=$2;
$path=$3;

#formatto la stringa per il comando nicl
$path =~s/[\/]+/\\\\\//g;

#debug
print "stringa=$entry \n";
print "mount=$1\n, host=$2\n, path=$3\n esubero=$4\n";
print "path=$path\n";
print "nicl . create /mounts/$host:$path\n";
print "nicl . -append /mounts/$host:$path type nfs\n";
print "nicl . -append /mounts/$host:$path dir $mount\n";
print "nicl . -append /mounts/$host:$path opts '-P'\n";

#inserisco i dati nel db netinfo
if ( defined($host)&&  defined($path) &&  defined($mount))
 {
system "nicl . create /mounts/$host:\\$path";
system "nicl . -append /mounts/$host:\\$path type nfs";
system "nicl . -append /mounts/$host:\\$path dir $mount";
system "nicl . -append /mounts/$host:\\$path opts '-P'";
#system "$NICL_APPEND dir $mount";
#system "$NICL_APPEND opts '-P'";
$i=$i+1;
print " ho inserito: $host, siamo a $i\n";

}
}
close MOUNT_STAT;

#riavvio automount
system "kill -1 `cat /var/run/automount.pid`";
#/usr/sbin/automount -f -m /Network/Servers -fstab -m /automount -static

print "ne ho inseriti $i\n";
