manage_dirs_permissions.sh.template 1.27 KB
Newer Older
1
2
#!/bin/bash

Sergio Bruni's avatar
Sergio Bruni committed
3
4
5
6
7
8
9
10
11
12
13
14
15
#-------------------------------------------------------------------------
# - Search for all network folders 
# - check if folders with name log and stf exist 
# - if folder exists:
#		1) delete Its contens 
#		2) change the owner to sergio.gnss 
#		3) change the permissions to 664
#
# - if folder does not exist:
#		1) create it  
#		2) assign the owner to sergio.gnss 
#		3) assign the permissions to 664
# 
Sergio Bruni's avatar
Sergio Bruni committed
16
17
18
# run this script whit sudo: sudo ./manage_dirs_permissions.sh
# because only root can change the group-owner of a folder 	
#
Sergio Bruni's avatar
Sergio Bruni committed
19
20
21
22
23
24
25
26
27
28
29
# 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[@]}"
30
do
Sergio Bruni's avatar
Sergio Bruni committed
31
32
33
34
35
36
37
38
	echo "manage $root ..." 
	for net in $(ls -t ${root}*/ | sort) ; do
		echo "	manage $net ..."
		for folder in "${folders_array[@]}"
		do
			full_folder="$root/$net/$folder"
			
			if [ -d "$full_folder" ]; then
Sergio Bruni's avatar
Sergio Bruni committed
39
				echo "		$full_folder exists ..."
Sergio Bruni's avatar
Sergio Bruni committed
40
41
42
43
				rm -f ${full_folder}/*
			else
				echo "		$full_folder does not exist ..."
			  mkdir ${full_folder}
44
			fi
Sergio Bruni's avatar
Sergio Bruni committed
45
46
47
			
			sudo chgrp gnss ${full_folder}
			chmod 664 ${full_folder}
48
49
50
		done
	done
done
Sergio Bruni's avatar
Sergio Bruni committed
51