FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 09-24-2008, 01:59 PM
"Brian McKee"
 
Default logging a bash script using sudo and time

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?

Brian


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 09-24-2008, 02:19 PM
"Eugene V. Lyubimkin"
 
Default 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
 
Old 09-24-2008, 04:08 PM
"Brian McKee"
 
Default 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!

---
==> time sudo echo 'hi mom' 2>&1 | logger -i -f /var/log/test.log

real 0m0.018s
user 0m0.000s
sys 0m0.016s

==> cat /var/log/test.log

---
==> time sudo echo 'hi mom' 2>&1 | logger -i -f /var/log/test.log

==> cat /var/log/test.log

---
==> time sudo echo 'hi mom' 2>&1 | logger -i -f /var/log/test.log
Password:

real 0m2.835s
user 0m0.004s
sys 0m0.014s

==> cat /var/log/test.log
hi mom

---

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
 
Old 09-25-2008, 06:17 PM
Michelle Konzack
 
Default 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)


Thanks, Greetings and nice Day/Evening
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant


--
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)
 
Old 09-26-2008, 03:50 PM
"Brian McKee"
 
Default 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
 
Old 09-26-2008, 10:17 PM
"Javier Barroso"
 
Default 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
 
Old 09-26-2008, 10:17 PM
"Javier Barroso"
 
Default 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
 

Thread Tools




All times are GMT. The time now is 06:48 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org