-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathxp_user_limit.sh
31 lines (27 loc) · 872 Bytes
/
xp_user_limit.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
#!/bin/bash
#XPanel Alireza
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <add/del> <username> <max_logins>"
exit 1
fi
action="$1"
username="$2"
max_logins="$3"
if [ ! -f "/etc/security/limits.conf" ]; then
echo "Error: /etc/security/limits.conf not found."
exit 1
fi
if [ "$action" = "add" ]; then
if grep -q "^$username " /etc/security/limits.conf; then
awk -v username="$username" -v max_logins="$max_logins" '$1 == username {$4 = max_logins} 1' /etc/security/limits.conf > /tmp/limit>
else
echo "$username hard maxlogins $max_logins" >> /etc/security/limits.conf
fi
echo "User $username limit set to $max_logins"
elif [ "$action" = "del" ]; then
sed -i "/^$username /d" /etc/security/limits.conf
echo "User $username limit removed"
else
echo "Unknown action: $action. Please use 'add' or 'del'."
exit 1
fi