-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-uset.sh
114 lines (100 loc) · 2.46 KB
/
setup-uset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
GREEN="\033[1;32m"
NOCOLOR="\033[0m"
if [ $1 == "-h" ]; then
echo "usage: ./create_users_account username [--dacc defaultaccount cpuhours] [--acc account cpuhours] [--qos qos]"
exit 0
fi
if [ $1 ]; then
if ! id $1 > /dev/null 2>&1; then
echo error: "\"$1\" user doesn't exit"
exit 1
fi
if [[ "$1" == [^\-\-] ]]; then
echo the first argument should be the username
echo "usage: ./create_users_account username [--dacc defaultaccount cpuhours] [--acc account cpuhours] [--qos qos]"
exit 1
fi
USER="$1"
fi
shift 1
while [ : ];do
if [ "$1" == "--acc" ]; then
if [ ! $2 ] || [[ "$2" == [^\-\-] ]]; then
echo acc option requires an argument
exit 1
fi
echo $3
if [[ $3 =~ [0-9] ]]; then
echo salam
ACPUHOURS=$3
shift 1
fi
argrexist=true
ACCOUNT=$2
elif [ "$1" == "--dacc" ]; then
if [ ! $2 ] || [[ "$2" == [^\-\-] ]]; then
echo dacc option requires an argument
exit 1
fi
if [[ $3 =~ [0-9] ]]; then
DACPUHOURS=$3
shift 1
fi
argrexist=true
DEFAULTACCOUNT="$2-account"
elif [ "$1" == "--qos" ]; then
if [ ! $2 ] || [[ "$2" == [^\-\-] ]]; then
echo qos option requires an argument
exit 1
fi
argrexist=true
QOS=$2
else
break
fi
shift 2
done
if [ ! $argrexist ] ; then
echo too few arguments
echo "usage: ./create_users_account username [--dacc defaultaccount cpuhours] [--acc account cpuhours] [--qos qos]"
exit 1
fi
if [ $ACCOUNT ]; then
echo -e "${GREEN}"
echo "sacctmgr add account $ACCOUNT"
echo -e ${NOCOLOR}
# sacctmgr add account $ACCOUNT
echo -e ${GREEN}
echo "sacctmgr add user $USER account=$ACCOUNT"
echo -e ${NOCOLOR}
# sacctmgr add user $USER account=$ACCOUNT
fi
if [ $DEFAULTACCOUNT ]; then
echo -e "${GREEN}"
echo "sacctmgr add account $DEFAULTACCOUNT"
echo -e ${NOCOLOR}
# sacctmgr add account $ACCOUNT
echo -e ${GREEN}
echo "sacctmgr add user $USER defaultaccount=$ACCOUNT"
echo -e ${NOCOLOR}
# sacctmgr add user $USER defaultaccount=$ACCOUNT
fi
if [ $QOS ]; then
echo -e ${GREEN}
echo "sacctmgr modify user $USER set qos=$QOS"
echo -e ${NOCOLOR}
# sacctmgr modify user $USER set qos=$4
fi
if [ $ACPUHOURS ]; then
echo -e ${GREEN}
echo "sbank deposit -c slurm_cluster -a $ACCOUNT -t $ACPUHOURS"
echo -e ${NOCOLOR}
# sbank deposit -c slurm_cluster -a $ACCOUNT -t $CPUHOURS
fi
if [ $DACPUHOURS ]; then
echo -e ${GREEN}
echo "sbank deposit -c slurm_cluster -a $DEFAULTACCOUNT -t $DACPUHOURS"
echo -e ${NOCOLOR}
# sbank deposit -c slurm_cluster -a $ACCOUNT -t $CPUHOURS
fi