6

I used below options in script to print on terminal as well as /var/log/messages

echo "System Load is OK : $Current_loadadv"
echo "System Load is OK : $Current_loadadv" | logger

but how can i do that in single line ?

6
tee >(logger) <<< "System Load is OK : $Current_loadadv"

>(logger) is bash syntax to create a file descriptor that is going to a FIFO, which is then fed to the standard input of logger (this is one form of what is known as "process substitution" in bash). It then passes back the path to that file descriptor as an argument to tee, and since tee writes to its non-option arguments, the FD is written to, and logger receives your string.

  • @RahulPatil: I don't know if that's actually the case, but as a mnemonic to remember tee, think of the letter T, it looks like a circuit splitter :) – Emanuel Berg Dec 25 '12 at 5:00
  • @EmanuelBerg Yes, that's the origin of the name tee. – Chris Down Dec 25 '12 at 11:22
3

Another Option :

logger -s "Message"

man logger

-s Log the message to standard error, as well as the system log.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.