fetch_file (version 1.0)
You can also look at:
#! /usr/bin/perl
##############################################################################
#
# SYNTAX: fetch_file dir file
#
# DESCRIPTION: This utility
# DESCRIPTION: copies the specified file from the specified directory
# DESCRIPTION: to the current directory.
# DESCRIPTION: It checks if the file exists in the current directory
# DESCRIPTION: and in the source directory.
#
# VERSION: 1.0
#
# HISTORY: 0.0 -> 1.0 1999-05-07
# HISTORY: Converted from ksh to perl
#
# CALLS: $UTIL/exception
# CALLS: $UTIL/log_entry
# CALLS: $UTIL/exit_test
#
##############################################################################
#$DEBUG=1;
($dir, $file) = @ARGV;
$UTIL = $ENV{"UTIL"};
####################
# debugging output
####################
if( "$DEBUG" ) {
print "fetch_file: dir=$dir\n";
print "fetch_file: file=$file\n";
}
############################################
# Check that file and directory are defined
############################################
if ( ! "$dir" ) {
`$UTIL/exception $0 1 "Source directory undefined"`;
exit 1;
}
if ( ! "$file" ) {
`$UTIL/exception $0 1 "File undefined"`;
exit 1;
}
if ( ! -e "$file" ) {
###############################################
# File does not exist yet in current directory
###############################################
`$UTIL/log_entry "Fetching ${file}"`;
system ("cp ${dir}/${file} .");
`$UTIL/exit_test $? $0 1 "While fetching ${file} from ${dir}"`;
}
else {
######################
# File already exists
######################
`$UTIL/log_entry "$file already present in current directory"`;
}
exit 0;