-
Notifications
You must be signed in to change notification settings - Fork 7
/
cyberpanel_sessions.sh
28 lines (22 loc) · 977 Bytes
/
cyberpanel_sessions.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
#!/bin/bash
# Iterate over all PHP versions installed.
for version in $(ls /usr/local/lsws | grep lsphp)
do
echo ""
echo "Processing PHP $version..."
# Fetch the session timeout value
session_time=$(/usr/local/lsws/${version}/bin/php -i | grep -Ei 'session.gc_maxlifetime' | grep -Eo "[[:digit:]]+" | sort -u)
if [ -z "$session_time" ]; then
echo "Failed to fetch session.gc_maxlifetime for PHP $version. Skipping..."
continue
fi
# Define the session path
session_path="/var/lib/lsphp/session/${version}"
if [ ! -d "$session_path" ]; then
echo "Session path $session_path does not exist. Skipping..."
continue
fi
# Delete expired sessions.
expired_sessions_count=$(find -O3 "$session_path" -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin +$((session_time / 60)) -print -delete | wc -l)
echo "Deleted $expired_sessions_count expired sessions for PHP $version."
done