#!C:/Perl/bin/perl use strict; # win_mount_dir_copy_file.pl # put hostnames in variable below, separated by a space. my @hostnames = qw(); my $SOURCE = ""; my $DESTINATION = ""; my $MOUNTLETTER = "G"; # An example of how using Perl to send commands makes looping easy # These are the Windows commands we want to use: # C:\>net use MOUNTLETTER: "\\hostname\sharename" # C:\>net use g: "\\hostname\c$" # C:\>mkdir "G:\Downloads" # example of copying from linux share # C:\>copy /Y \\hostname\directory_path\setup.exe "G:\Downloads" # example of copying from Windows share mounted on the "U" directory # C:\>copy /Y U:\hostname\directory_path\setup.exe "G:\Downloads" # C:\>net use g: /delete # we will increment the letter of the mounted drive so we don't have to worry # about network latency or sending the "sleep" command # Uncomment each of the for loops for the different computers in the lab for (@hostnames) { print my $host = $_; print "working on host $hostz\n"; my $hoststring = qq|\\\\$hostz\\c\$|; print "executing: net use $MOUNTLETTER: $hoststring \n\n"; `net use $MOUNTLETTER: $hoststring`; print "executing: Create Downloads dir on $MOUNTLETTER: \n\n"; `mkdir "$MOUNTLETTER:\Downloads"`; print "executing: Copying Install File from $SOURCE to $MOUNTLETTER:\Downloads \n\n"; `copy /Y \\$SOURCE $MOUNTLETTER:\Downloads`; # Now that the copy is complete, delete the $MOUNTLETTER to free it up for another use print "executing: net use $MOUNTLETTER: /delete \n\n"; `net use $MOUNTLETTER: /delete`; # increment the $MOUNTLETTER from G to H , for example # do this because it takes a while for the delete to complete # and we don't want the script to slow or error while waiting for a free mount point $MOUNTLETTER ++; # reset $MOUNTLETTER to "G" after it gets to "P" # because by now, G will be available again $MOUNTLETTER = "G" if ($MOUNTLETTER eq "P"); } print "Script complete\n"; exit (0);