90 lines
1.7 KiB
Bash
Executable File
90 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
source $HOME/.bwda
|
|
|
|
# Usage function
|
|
usage(){
|
|
echo "Usage: $(basename $0) files"
|
|
echo " files files to be downloaded"
|
|
echo " -c | --channel N use N channels per file"
|
|
echo " -n | --dry-run print commands to stdout instead of executing them"
|
|
echo " -P | --parallel N transfer N files in parallel"
|
|
echo " -h | --help display this message"
|
|
}
|
|
|
|
# Get command line argument
|
|
nparallel=1
|
|
nchannel=1
|
|
flag_dryrun=false
|
|
|
|
POSITIONAL=()
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
key="$1"
|
|
case $key in
|
|
-c|--channel)
|
|
nchannel="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-n|--dry-run)
|
|
flag_dryrun=true
|
|
shift
|
|
;;
|
|
-P|--parallel)
|
|
nparallel="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
shift
|
|
;;
|
|
*)
|
|
POSITIONAL+=("$1")
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
set -- "${POSITIONAL[@]}" # restore positional parameters
|
|
|
|
# Check if we got enough command line arguments
|
|
if [ $# -eq 0 ]; then
|
|
usage
|
|
exit -1
|
|
fi
|
|
|
|
# Get path to correct directory on bwda
|
|
ldir_target="$(realpath $PWD)"
|
|
if [[ $ldir_target == "${ldir_base}"* ]]; then
|
|
dir_target=${ldir_target#"$ldir_base"}
|
|
else
|
|
echo "Current directory is not located on LSDF!"
|
|
echo "Is the base directory setting correct?"
|
|
echo "ldir_base: $ldir_base"
|
|
exit -2
|
|
fi
|
|
rdir_target="${rdir_base}/${dir_target}"
|
|
|
|
# Construct command
|
|
cmd="open sftp://${bwda_acc}@${bwda_url}\n"
|
|
cmd+="set cmd:parallel ${nparallel}\n"
|
|
cmd+="cd ${rdir_target}\n"
|
|
cmd+="lcd ${ldir_target}\n"
|
|
for file in $*; do
|
|
cmd+="pget -n ${nchannel} $file\n"
|
|
done
|
|
cmd+="bye\n"
|
|
|
|
# Print or execute commands
|
|
if [ "$flag_dryrun" == true ]; then
|
|
printf "$cmd"
|
|
else
|
|
tmpfile=$(mktemp)
|
|
printf "$cmd" > $tmpfile
|
|
lftp -f $tmpfile
|
|
rm $tmpfile
|
|
fi
|
|
|
|
|