Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Track changes made with the defaults command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Track changes made with the defaults command
Authored by: dgerrity on Jul 11, '11 05:30:10PM
Interesting idea, because then you could log other specific commands as well, such as
history | grep "defaults\|plist\|sudo" | grep -v history | cut -c8-
I just tried it now and there were no default entries in my past 500, so with this approach you'd probably want to run the scan relatively frequently and possible deal with duplicates. One problem with this and a problem in general with my log function is that it can't really take the output of a command with multiple lines and log it "correctly". I have to do something like
log "port list outdated"; (IFS="|"; port list outdated | while read line; do log ${line}; done)
Suggestions on a better log function that could handle multiple lines but still keep the same prefix (date, user, function?)

[ Reply to This | # ]
Track changes made with the defaults command
Authored by: dgerrity on Aug 29, '11 11:50:04AM
An improvement on the log function and an answer to my own question about logging multi-line output For the log function, I indent with shell levels so you can see in the log when scripts call other scripts; also, because $0 is often "-bash" and the dash is interpreted as an option, I strip a leading dash from the name of the calling function.

log () {
    sp=$(printf "%$(((${SHLVL}-1)*4))s" " ");
    echo "$(date "+%Y-%m-%d %H:%M:%S")${sp}$(echo $0 | sed 's/^-//') $@" >> "${lf}"
And secondly, a way to put multiple lines into the log (duh):

port list installed | while read line; do log $line; done

[ Reply to This | # ]