> On 29 Oct 2014, at 20:54 , LuKreme <[email protected]> wrote:
>
> Sadly, that was a tyop introduced by trying to make the variable names for
> understandable for the post. This is the actual start of the script:
>
> LUSER=$1
> logger -t session "** LOGOUT SESSION FOR $LUSER started **"
> _PS=`ps axco "lstart,comm,user" | grep loginw `
Bah. There must have been some typo or stray character or something. After
making a few edits and adding some logging and a test or two, now the script
works as it did.
This is the current script, if anyone cares:
#!/bin/bash
LUSER=$1
#set > /tmp/logout.txt
_RUSER=`dscl . -read /Users/$LUSER RealName | tail -1`
logger -t usession "** LOGOUT usession FOR $LUSER started **"
#logger -t usession "** _RUSER is $_RUSER **"
if [ -x /opt/local/bin/gdate ]; then
_PS=`ps axco "lstart,comm,user" | grep loginw `
logger -t usession "** _PS = $_PS"
_START_TIME=`echo $_PS | awk '{print $3, $2, $5, $4 }'`
logger -t usession "** _START_TIME = $_START_TIME"
_START=`/opt/local/bin/gdate -d "$_START_TIME" "+%s"`
_END=`/opt/local/bin/gdate '+%s'`
_ELA=$((_END - _START))
_DAY=$((_ELA / 86400))
_HOU=$(((_ELA % 86400) / 3600))
_MIN=$(((_ELA % 86400 % 3600) / 60))
logger -t usession "** $_RUSER ($LUSER) logged in at $_START_TIME, (${_DAY}d
${_HOU}:${_MIN} ago)"
_NOGDATE=""
else
_NOGDATE="GNU Date is not installed"
fi
#logger -t usession "** RUser is \"$_RUSER\""
logger -t usession "** Changing fortune"
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow
LoginwindowText -string "$(/Users/kreme/bin/fortune -s /Users/kreme/mysigs)"
if [[ -z $_NOGDATE ]]; then
/usr/bin/osascript <<EOF
set myName to "$_RUSER"
set myDays to "$_DAY"
set myHours to "$_HOU"
set myMinutes to "$_MIN"
-- #set mySeconds to "$_SEC"
set myTime to "You usession lasted "
set myD to " days "
set myH to " hours "
set myM to " minutes "
-- #set myS to " seconds "
if myDays is "1" then myD = " day "
if myHours is "1" then myH = " hour "
if myMinutes is "1" then myM = " minute "
-- #if mySeconds is "1" then myS = " second "
if myDays is "0" then
if myHours is "0" then
set myTime to myTime & myMinutes & myM
else
set myTime to myTime & myHours & myH & myMinutes & myM
end if
else
set myTime to myTime & myDays & myD & myHours & myH & myMinutes & myM
end if
say "Goodbye," & myName & "! " & myTime using "Alex" speaking rate 300 volume 1
EOF
else
say "Goodbye $_RUSER. $_NOGDATE"
fi
logger -t usession "** LOGOUT usession FOR $LUSER COMPLETED **"
--
Dinosaurs are attacking! Throw a barrel!
_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk