Hi,
Code:
#!/bin/sh -e
max=1440
# look for the php.ini file(s) in /etc/php5/*/ (all the subdirs in /etc/php5/)
for ini in /etc/php5/*/php.ini; do
# fill cur with
# 1) the content of this variable session.gc_maxlifetime
# 2) if it is not found fill cur with nothing (null) (the || true part)
cur=$(sed -n -e
's/^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$/\1/p' $ini 2>/dev/null || true);
# if cur is null, fill cur with zero
[ -z "$cur" ] && cur=0
# if cur is greater then max, fill max with value of cur
[ "$cur" -gt "$max" ] && max=$cur
done
# echo value of max (devided by 60 is in minutes, the value of session.gc_maxlifetime is set in seconds in php.ini)
echo $(($max/60))
# stop the script with a successful status
exit 0
About the sed part:
^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$
The above looks for
session.gc_maxlifetime and its value
[0-9]\+ and takes into consideration that there could be tabs or spaces before and after the values (the
[[:space:]] parts. It also has to be on a line by itself (^ -> beginning of the libe and the closing $ -> end of the line).
The \1 in the replace part prints what is found between the \( and \) in the search part (this is called back referencing).
Hope this helps.