#!/usr/bin/perl # # zcp - copy a file from the global zone to a nonglobal zone. Solaris 10. # # 10-Mar-2005, ver 0.50 (first release) # # USAGE: zcp file1 zonename:file2 # eg, # zcp /etc/syslog.conf workzone1:/tmp # # # Standard Disclaimer: This is freeware, use at your own risk. # # 10-Mar-2005 Brendan Gregg Created this. # $ENV{PATH} = "/usr/bin:/usr/sbin"; $VERBOSE = 1; # # Process arguments # # check for arguments, if (@ARGV != 2) { die "USAGE: zcp file1 zonename:file2\n"; } # check source file exists, $srcpath = $ARGV[0]; if (! -e $srcpath) { die "ERROR1: Can't find source file $srcpath\n"; } # check destination zone exists, ($destzone,$destpath) = split(/:/,$ARGV[1]); chomp(@Zones = `zoneadm list`); foreach $zone (@Zones) { $Zone{$zone} = 1; } unless ($Zone{$destzone}) { die "ERROR2: Can't find zone $destzone\n"; } # check if destination is a directory or filename, $dir = `zlogin -S $destzone ' if [ -d "$destpath" ]; then echo 1; else echo 0; fi'`; if ($dir == 1) { $node = $srcpath; $node =~ s:.*/::; $destpath = "$destpath/$node"; } # # Print message # print "zcp from $srcpath, to zone $destzone, to file $destpath.\n" if $VERBOSE; # # Copy File # system("cat $srcpath | zlogin -S $destzone 'cat - > $destpath'"); # # Verify file copied # $srcsize = -s $srcpath; $destinfo = `zlogin -S $destzone 'ls -l $destpath'`; @Fields = split(' ',$destinfo); $destsize = $Fields[4]; if ($srcsize != $destsize) { print STDERR "ERROR3: Copy failed, size mismatch ". "($srcsize != $destsize)\n"; } else { print "Copy successful ($destpath, $destsize bytes).\n" if $VERBOSE; }