# mvshare.pl moves a share from \\AXPA to \\SFD_SRV1. Transposes any path # references from C: to D: and E: to F: in new share definition. # Calls the following external commands: RCMD, NET SHARE, SCOPY, PERMCOPY. # Written 22-Jan-1998 by fhb. # Mod 31-jan-1998 by fhb: copy all files regardless. # # Usage: mvshare sharename | filename # # required arg: sharename or filename. # If arg is filename, it must contain a list of sharenames, 1 per line. # Lines beginning with a '!' are ignored as comments. $bDebug = 0; $sOldServer = "\\\\axpa"; $sNewServer = "\\\\sfd_srv1"; $sTempFile = "t.t"; MAIN: $sAppName = "mvshare"; $sVersion = "0.1"; print "$sAppName $sVersion\n"; $sFile = $ARGV[0]; if (!$sFile) { die "No share or filename supplied.\n"; } if (open(FDATA,$sFile)) { while () { if (!/^\!/) { # skip comments chop; ($sShare,$sJunk) = split; print "Moving share $sShare...\n"; &CopyShare(); } } } else { # arg not a file, so try single share: $sShare = $ARGV[0]; &CopyShare(); } print "$sAppName: share $sShare moved from $sOldServer to $sNewServer.\n"; ##### subroutines follow: ##### sub CopyShare { # Capture NET SHARE output in temp file: $sCmd = sprintf("rcmd %s net share %s >%s",$sOldServer,$sShare,$sTempFile); if ($bDebug) { print "dbg> $sCmd\n"; } system($sCmd); open(FTEMP,$sTempFile) || print "Can't open file $sTempFile: $!\n"; #read(FTEMP,$sData,100); while () { chop $_; if (/^Path (.*)/) { $sPath = substr($_,18); $chDrive = substr($sPath,0,1); $sRestOfPath = substr($sPath,1); if ($chDrive eq 'C' || $chDrive eq 'c') { $chNewDrive = "D"; } elsif ($chDrive eq 'E' || $chDrive eq 'e') { $chNewDrive = "F"; } $sNewPath = sprintf("%s%s",$chNewDrive,$sRestOfPath); last; } } close(FTEMP); unlink $sTempFile; if ($sPath eq "") { die "Can't find share $sShare!\n"; } $_ = $sPath; s/:/\$/; $sPath = $_; $_ = sprintf("%s\\%s",$sNewServer,$sNewPath); s/:/\$/; if (! -e) { # create dir if it doesn't exit if ($bDebug) { print "dbg> mkdir $_\n"; } else { print "creating directory $_...\n"; mkdir($_,umask); } } # Copy all the files with security attributes: $sCmd = sprintf("scopy %s\\%s\\*.* %s /o /s",$sOldServer,$sPath,$_); if ($bDebug) { print "dbg> $sCmd\n"; } else { system($sCmd); } # Create the new share: $sCmd = sprintf("rcmd %s net share %s=%s",$sNewServer,$sShare,$sNewPath); if ($bDebug) { print "dbg> $sCmd\n"; } else { print "creating share on $sNewServer...\n"; system($sCmd); } # Copy permissions: $sCmd = sprintf("permcopy %s %s %s %s",$sOldServer,$sShare,$sNewServer,$sShare); if ($bDebug) { print "dbg> $sCmd\n"; } else { print "\ncopying permissions..."; system($sCmd); } # Delete old share: $sCmd = sprintf("rcmd %s net share %s /delete",$sOldServer,$sShare); if ($bDebug) { print "dbg> $sCmd\n"; } else { print "\ndeleting share from $sOldServer..."; system($sCmd); } }