best logging method for scripts

tlarkin
Honored Contributor

I have been scrapping my scripts and combining them all into 1 post image script for configurations that are just needed. What I cannot do in MCX I do via shell scripts. However, combining them all racks up like 500 lines of code sometimes. I would like the output of all commands to log to a log file, and remain there unless the script finishes. The last line in the script wipes out the log files. I have looked at the logger command, tee, script, using stdout, and so forth.

Not really sure the best way to go. Also, anyone know how to say have it populate the imaging logs in the JSS? That would be nice too, as sometimes I remotely image machines.

Thanks

Tom

4 REPLIES 4

Not applicable

I have been scrapping my scripts and combining them all into 1 post image
script for configurations that are just needed. What I cannot do in MCX I
do via shell scripts. However, combining them all racks up like 500 lines
of code sometimes. I would like the output of all commands to log to a
log file, and remain there unless the script finishes. The last line in the
script wipes out the log files. I have looked at the logger command, tee,
script, using stdout, and so forth. Not really sure the best way to go. Also, anyone know how to say have it
populate the imaging logs in the JSS? That would be nice too, as sometimes
I remotely image machines.

I like this method for having a script log.

set -xv; exec 1>/Location/to/save/log.txt 2>&1

This shows the line that's executed and then under that shows any messages
coming back from the command. Cant help you with populating the JSS logs
though. HTH

- JD

stevewood
Honored Contributor II
Honored Contributor II

Okay, I can plug through scripts fairly well, but I'm a little unsure on
this. Where exactly in a shell script would you put this line? Would it go
at the top of the script?

Steve Wood
Director of IT
swood at integer.com

The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475

abenedict
New Contributor II

I put it where I would have my very first command, I believe that is starts
logging from the point that it is ran, very handy.

--
Alan Benedict
?
Macintosh Technician
The Integer Group
http://www.integer.com

Not applicable

Yes, I put this right after my shebang line so it will log every command
from that point down.

- JD