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


Click here to return to the 'Making a log?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Making a log?
Authored by: tamenti on Mar 13, '03 11:12:41AM

How do I make a log with the info given by this script?
% ./scriptname > battery.log
Puts the output of the script into the file, but how do I append new data to the end of the file and maybe add a timestamp? Can it be done in a single command or would it have to be build into the script itself?

Oh, and, by the way, my almost-a-year-old iBook 600 gives this:
voltage=11384 flags=4/0x004 amperage=1110 capacity=2054 current=1690 [82.3%]
So if I read the knowledgebase right, my book is a at about half capacity?



[ Reply to This | # ]
Making a log?
Authored by: jpryor68 on Mar 13, '03 11:30:59AM
How do I make a log with the info given by this script?
% ./scriptname > battery.log
Puts the output of the script into the file, but how do I append new data to the end of the file and maybe add a timestamp? Can it be done in a single command or would it have to be build into the script itself?

This appends a timestamp and scriptname's output to a log file:
% date;scriptname >> logfile.log

[ Reply to This | # ]

Shell Scripting
Authored by: ktohg on Mar 13, '03 07:26:24PM

Don't wish to intrude but this will not work as expected

The semi coloen is a command delimeter so the date command will have default input and output where as the other command will have output redirected to the log file.

To accomplish what you wish you can do it two ways. (The first I belive may not be supported in every shell.

% (date ; scriptname) >> logfile.log

or

% date >> logfile.log ; scriptname >> logfile.log

[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:31:39AM

you could do something like:

echo `date; scriptname;` >> battery.log

If you do ">>" instead of ">" it will append to the end of the file rather than overwriting it. By enclosing two commands inside the backticks "``" these two commands will be executed, returning their output. Putting "echo" in front of it will dump out the results as text (otherwise the shell would try to execute the returned text).



[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:35:58AM

Ah yes. The "echo" can be safely omitted when using csh, though it won't hurt to have it in there. With bash, you have to include it or it won't work.



[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:41:32AM

*sigh* nevermind. Don't omit the "echo". You'll need the entire command as I originally posted it, in both csh and bash. Otherwise, either you won't get the timestamp in the log file, or the shell will try to execute the resulting text.



[ Reply to This | # ]