Reputation: 21
http://www.webdesignerdepot.com/rss.htm
I have the same issue. This command:
./somescript.sh > ../log/scriptlog.log
requires the output of a command go to std out. but inside the script
command | mailx -s "Subject" [email protected]
what I would like to do is something like :
command | tee > /dev/stdout | mailx -s "Subject" [email protected]
Where the output of the command goes to stdout( to be redirected into the ..log/scriptlog.log file )
and also into stdin for the mailx command.
Any way to do that?
Upvotes: 2
Views: 863
Reputation: 1
I'll try process substitution. To clarifily, I have a cron'd shell script . The cron entry is similar to: /usr/script/myscript.sh > /usr/log/myscript.log
inside the script is a line similar to: command | mailx -s "Subject" recipient
Since stdout from 'command' is being piped into the mailx command, it does appear in the log file 'myscript.log', but I want it to.
I tried capturing it into a variable but the line feeds appear to be lost that way. I could use a temporary file, but I was hoping for something more elegant.
Upvotes: 0
Reputation: 4827
exec 3>&1
command | tee /dev/fd/3 | mailx ...
or, using process substitution:
command | tee >(mailx ...)
Upvotes: 1
Reputation: 799130
tee
already sends to stdout.
... | tee -a log/scriptlog.log | ...
Upvotes: 1