Commit d983b849 authored by Sergio Bruni's avatar Sergio Bruni
Browse files

manage_dirs_permissions.sh

parent f9126e94
#!/bin/bash #!/bin/bash
while getopts n:y: option
do
case "${option}"
in
n) net_or_all=${OPTARG};;
y) year_or_all=${OPTARG};;
esac
done
if ! [ -n "${net_or_all+set}" ]; then
echo 'insert network name or all'; exit 1
fi
if ! [ -n "${year_or_all+set}" ]; then
echo 'insert year YYYY or all'; exit 1
fi
shopt -s nocasematch
re="^(all|[0-9]{4}+)$"
if ! [[ $year_or_all =~ $re ]] ; then
echo "insert year in four digit form or all"; exit 1
fi
net_or_all=${net_or_all^^}
year_or_all=${year_or_all^^}
in_root="/mnt/data/archive/rinex/CGPS/NETS"
net_array=() #-------------------------------------------------------------------------
# - Search for all network folders
if [[ $net_or_all == 'ALL' ]] # - check if folders with name log and stf exist
then # - if folder exists:
for my_net in $(ls -t ${in_root}*/ | sort) ; do # 1) delete Its contens
net_array+=($my_net) # 2) change the owner to sergio.gnss
done # 3) change the permissions to 664
else #
net_array+=($net_or_all) # - if folder does not exist:
fi # 1) create it
# 2) assign the owner to sergio.gnss
re_anno='^[0-9]{4}+$' # 3) assign the permissions to 664
#
for net in "${net_array[@]}" # Author: Sergio Bruni - sergio.bruni@ingv.it
#-------------------------------------------------------------------------
roots_array=()
roots_array=(/mnt/data/archive/rinex/CONTINUOUS/30s)
roots_array+=(/mnt/data/archive/rinex/CAMPAIGN/30s)
folders_array=(log stf)
for root in "${roots_array[@]}"
do do
# se richieste tutte le reti salto la RING echo "manage $root ..."
# cosa temporanea for net in $(ls -t ${root}*/ | sort) ; do
if [ $net_or_all == 'ALL' ] && [ $net == "RING" ] ; then echo " manage $net ..."
echo "SKIP RING" for folder in "${folders_array[@]}"
continue do
fi full_folder="$root/$net/$folder"
year_array=()
if [[ $year_or_all == 'ALL' ]]; then if [ -d "$full_folder" ]; then
for my_year in $(ls -t ${in_root}/${net}*/ | sort) ; do rm -f ${full_folder}/*
if [[ $my_year =~ $re_anno ]] ; then else
# se richiesti tutti gli anni per ora salto 2015/16/17 echo " $full_folder does not exist ..."
if [ ${my_year} -ne '2015' ] && [ $my_year -ne '2016' ] && [ $my_year -ne '2017' ] && [ $my_year -ne '2018' ] && [ $my_year -ne '2019' ] ; then mkdir ${full_folder}
year_array+=($my_year)
else
echo "SKIP ${my_year}"
fi
fi fi
sudo chgrp gnss ${full_folder}
chmod 664 ${full_folder}
done done
else
# e' stato chiesto un solo anno
if [ -d ${in_root}/${net}/${year_or_all} ] ; then
year_array+=($year_or_all)
else
echo "folder ${in_root}/${net}/${year_or_all} do not exists"
continue
fi
fi
for year in "${year_array[@]}" ; do
echo "./populateLog.py -e excluded_${net}_${year} -n $net -y $year -H gnssgiving.int.ingv.it -U sergio -P p0wer2017 -a -r /mnt/data/archive/rinex/CGPS/NETS"
./populateLog.py -e excluded_${net}_${year} -n "$net" -y "$year" -H gnssgiving.int.ingv.it -U sergio -P p0wer2017 -a -r /mnt/data/archive/rinex/CGPS/NETS
done done
done done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment