bwdatools/bwdals

58 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
source $HOME/.bwda
# Usage function
usage(){
echo "Usage: $(basename $0) [opt]"
echo "List the contents of the current directory on bwda."
echo "Options are directly passed to lftp's ls command with the following exceptions:"
echo " -h | --help display this message"
}
# Get command line argument
nparallel=1
nchannel=1
flag_printcommands=false
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
usage
exit 0
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# 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+="cd ${rdir_target}\n"
cmd+="ls ${POSITIONAL[@]}\n"
cmd+="bye\n"
# Execute commands
tmpfile=$(mktemp)
printf "$cmd" > $tmpfile
lftp -f $tmpfile
rm $tmpfile