Skip to content

Instantly share code, notes, and snippets.

@init-js
Created September 24, 2019 17:41
Show Gist options
  • Save init-js/7928513903149a4688ff66677c6e04d8 to your computer and use it in GitHub Desktop.
Save init-js/7928513903149a4688ff66677c6e04d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# This script refreshes the access time of files and folders
#
# update this list with the files and folders you wish to preserve.
# folders will be traversed recursively.
files=(
/scratch/jslegare/refresh.sh
/scratch/jslegare/{bams_Melis,melis-call,Melis}
/scratch/jslegare/data
/scratch/jslegare/{gowens-call,issue_43}
/scratch/jslegare/sra_test
/scratch/jslegare/subset_variants_522
/scratch/jslegare/sunrise
)
case "$1" in
y)
:
;;
*)
echo "pass y as an argument to refresh files" >&2
exit 0
;;
esac
set -exo pipefail
shbin=$(which bash)
errorlog=refresh_errors.$$.txt
for d in "${files[@]}"; do
[[ -e "$d" ]]
echo "DIR $d"
# -a: access time only
# -c: no-create
find "$d" -print -exec "$shbin" -c 'touch -a -c "$0" || echo ERROR "$0" >&2' '{}' ';' 2>"$errorlog"
if [[ -s "$errorlog" ]]; then
echo "errors occurred." >&2
exit 1
fi
done
rm "$errorlog"
echo "all done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment