#!/usr/bin/perl -w # get the command line arguments $ARGC = $#ARGV + 1; if ($ARGC != 1) { die "Usage: $0 [directory]\n"; } # first argument is the directory to submit $dir = $ARGV[0]; # this is the class submissions directory $submitdir = "/usr/class/cs101/submitdir"; # figure out who the user is $username = `/usr/pubsw/bin/whoami`; chomp($username); # ensure that the argument to this script only consists of # letters, digits, dots, slashes, and underscores if ($dir =~ /^([\w\.\/\_]*)$/) { # create the submit directory for the user if it doesn't exist $targetdir = "$submitdir/$username/"; mkdir $targetdir; # copy the directory over print "Recursively copying $dir to $targetdir\n"; system("cp -r $dir $targetdir"); } else { print "Malicious input: submit failed!\n"; }