alt.os.linux.ubuntu

Re: who command date format in script


Aragorn wrote:
> True, and setting" LC_ALL=C" isn't necessarily going to solve it either.
> You don't even need LC_ALL explicitly, but only LC_DATE and possibly
> LC_CTYPE, and they should not necessarily be set to "C" - which /should/
> normally be the same as setting them to "POSIX" - but to the same values
> as what the system is set up with by default for all users, assuming
> that the OP is not using a separate setting for his own user account.
>
> Setting LC_ALL is to be avoided anyway, because it overrides all other
> LC_* settings. On my systems, LC_ALL is declared but not set.
>
My solution was to fork, then best I could come up with:
....
#First check if date format is alpha or numeric in the 3rd TIME field
TIMES=$(who -u | egrep "${USERSLIST}" | tr -s ' ' | cut -d ' ' -f 3)
# Test the first character of the first entry
if [[ "${TIMES[0]:0:1}" =~ [0-9] ]]; then
FIELD=6 # numeric so PID the 6th field
else
FIELD=7 # alpha so PID is the 7th field
fi
# Now get the session PIDs of the selected users from the correct field
PIDS=$(who -u | egrep "${USERSLIST}" | tr -s ' ' | cut -d ' ' -f $FIELD)
# Now kill the found sessions
for PID in ${PIDS[_at_]}
do
kill ${PID}
done
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com




Written by "Jonathan N. Little" 20/10/2011 0.39.07
Check some pics on this site!
23/05/2012 5.18.23