I regularly run a script with time and sudo. e.g.
> time sudo echo 'hi mom'
I've set up the sudoers file so that one script (represented in my
example as `echo`) can be run as sudo by my user account without a
password prompt.
Now I want to log the entire output to a log file as well as display
it on the screen.
> time sudo echo 'hi mom' | tee | logger -f /var/log/hiMom
Only that doesn't work :-) Time is only on the screen, not in the log
file, and /var/log/hiMom is empty, regardless of the permissions on
that file.
Can someone explain the redirection going on here in a way I can grok?
Brian
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
09-24-2008, 02:19 PM
"Eugene V. Lyubimkin"
logging a bash script using sudo and time
Brian McKee wrote:
> Hi All
>
> I regularly run a script with time and sudo. e.g.
>> time sudo echo 'hi mom'
[snip]
> Now I want to log the entire output to a log file as well as display
> it on the screen.
>> time sudo echo 'hi mom' | tee | logger -f /var/log/hiMom
>
> Only that doesn't work :-) Time is only on the screen, not in the log
> file, and /var/log/hiMom is empty, regardless of the permissions on
> that file.
>
> Can someone explain the redirection going on here in a way I can grok?
'time' writes output to stderr, use "time sudo echo 'hi mom' 2>&1"
And why "logger -f"? Just "tee /var/log/hiMom".
--
Eugene V. Lyubimkin aka JackYF
09-24-2008, 04:08 PM
"Brian McKee"
logging a bash script using sudo and time
On Wed, Sep 24, 2008 at 10:19 AM, Eugene V. Lyubimkin
<jackyf.devel@gmail.com> wrote:
> Brian McKee wrote:
>> I regularly run a script with time and sudo. e.g.
>>> time sudo echo 'hi mom'
> [snip]
>> Now I want to log the entire output to a log file as well as display
>> it on the screen.
>>> time sudo echo 'hi mom' | tee | logger -f /var/log/hiMom
>> Only that doesn't work :-) Time is only on the screen, not in the log
>> file, and /var/log/hiMom is empty, regardless of the permissions on
>> that file.
>> Can someone explain the redirection going on here in a way I can grok?
> 'time' writes output to stderr, use "time sudo echo 'hi mom' 2>&1"
> And why "logger -f"? Just "tee /var/log/hiMom".
Aha! Thanks - I didn't know time used stderr and I didn't think about
that being a possibility.
I have logger in there because I was considering whether to put the
output in syslog, or a file in /var/log, and either way I like the
formatting you get with the -i option.
Now I've really confused myself. I ran it without the tee on three
different systems (buntu, Mandrake, a nameless proprietary OS) and got
three different answers!
Poking around seems to indicate that the -i option doesn't work when
used in combination with the -f option, but I can't explain the
differences in output past that. Jeez, I thought this would be easy!
Brian
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
09-25-2008, 06:17 PM
Michelle Konzack
logging a bash script using sudo and time
Am 2008-09-24 09:59:26, schrieb Brian McKee:
> Hi All
>
> I regularly run a script with time and sudo. e.g.
> > time sudo echo 'hi mom'
>
> I've set up the sudoers file so that one script (represented in my
> example as `echo`) can be run as sudo by my user account without a
> password prompt.
>
> Now I want to log the entire output to a log file as well as display
> it on the screen.
> > time sudo echo 'hi mom' | tee | logger -f /var/log/hiMom
>
> Only that doesn't work :-) Time is only on the screen, not in the log
> file, and /var/log/hiMom is empty, regardless of the permissions on
> that file.
>
> Can someone explain the redirection going on here in a way I can grok?
time sudo (echo 'hi mom' | tee | logger -f /var/log/hiMom)
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
09-26-2008, 03:50 PM
"Brian McKee"
logging a bash script using sudo and time
On Thu, Sep 25, 2008 at 2:17 PM, Michelle Konzack
<linux4michelle@tamay-dogan.net> wrote:
> time sudo (echo 'hi mom' | tee | logger -f /var/log/hiMom)
==> time sudo (echo 'hi mom' | tee | logger -f /var/log/hiMom)
-bash: syntax error near unexpected token `echo'
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
09-26-2008, 10:17 PM
"Javier Barroso"
logging a bash script using sudo and time
On Wed, Sep 24, 2008 at 4:19 PM, Eugene V. Lyubimkin
<jackyf.devel@gmail.com> wrote:
> Brian McKee wrote:
> ...
>> Can someone explain the redirection going on here in a way I can grok?
> 'time' writes output to stderr, use "time sudo echo 'hi mom' 2>&1"
I would use:
{ time sudo echo 'hi mon' } 2> file.log
I don't know why it is needed '{' trick.
Regards
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
09-26-2008, 10:17 PM
"Javier Barroso"
logging a bash script using sudo and time
I forget the semicolon:
{ time sudo echo 'hi mon' ; } 2> file.log
On Sat, Sep 27, 2008 at 12:17 AM, Javier Barroso <javibarroso@gmail.com> wrote:
> On Wed, Sep 24, 2008 at 4:19 PM, Eugene V. Lyubimkin
> <jackyf.devel@gmail.com> wrote:
>> Brian McKee wrote:
>> ...
>>> Can someone explain the redirection going on here in a way I can grok?
>> 'time' writes output to stderr, use "time sudo echo 'hi mom' 2>&1"
>
> I would use:
>
> { time sudo echo 'hi mon' } 2> file.log
>
> I don't know why it is needed '{' trick.
>
> Regards
>
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org