Hey folks, I’m a php dev who has fumbled in here and needs a little assistance. This is my first post, so please let me know if I’m in the wrong place, or breaking etiquette.
My issue is very simple, I need to track the user, time logged on and time logged off in a text file. This mac is hooked to a machine used for research and we bill based on the amount of time logged on. Once I get the text file formatted I can write the rest in php.
My basic script looks like this
logon:
do shell script "whoami >> $MacHD/LogApplicationUse/OpenDoc.txt"
do shell script "date >> $MacHD/LogApplicationUse/OpenDoc.txt"
logoff:
#!/bin/bash
osascript -e 'do shell script "date >> $MacHD/LogApplicationUse/OpenDoc.txt"'
osascript -e 'do shell script "var=out; echo $var >> $MacHD/LogApplicationUse/OpenDoc.txt"'
This works great for output like this:
user
time in
time out
user
time in
time out
But I’d really like it in this format:
user, time in, time out
user, time in, time out
I started goofing around and came up with this (untested):
Code:
set user to do shell script "whoami"
set log_in to do shell script "date"
set line to user & ", " & log_in ", "
do shell script "line >> $MacHD/LogApplicationUse/OpenDoc.txt"
for my login, which should get me halfway, but even if it works, I’m still stuck with my logout script starting on a new line:
user, time in,
time out
user, time in,
time out
Can someone point me in the right direction here? The >> appends to the file, however it does so with a line break:
will write over the existing data
will append, but it does so with a carriage return
Thanks in advance for any suggestion you all might have, my searches have been less than fruitful.