ksh- redirect stderr to file and then modify the file

I have the following:

remsh $host -n 2>>syslog_issue_list.txt grep -i -e "EMS" -e "error" -e "warning" -e "excessive" /var/adm/syslog/syslog.log |
awk /"$DATE1"/ | awk -vhost="$host" '!/remsh|telnetd/{print host "\n", $0 >> "syslog_issue_list.txt"}'

I am creating a health script that has numerous health checks in it. This check is looking at a remote host's syslog for certain words (EMS, error, etc..). I am then using awk to print the hostname of the remote host and then errors that i searched for in the syslog.

As you can see, I redirected stderr to syslog_issue_list.txt in order to catch certain errors which did not show up in teh awk statement. I was wondering if it is possible to redirect stderr, to that file, and then immediately put in before/after the syslog_issue_list.txt file the hostname that is producing the error.

For example, the redirection will show errors like this:

remshd: Login Incorrect

I have dozens of hosts to check and I will have no clue which host created that error entry. I would like the stderr redirect to the error log to show:

HOSTNAME remshd: Login Incorrect

Anyone have any ideas? Thanks

You mean, redirect stderr to more than one file?

You can't redirect one file to more than one place, you have to use utilities like tee to read one file descriptor and write to two.

This will definitely mess up the timing of the messages.

Not redirect to more than one file. I would like to have stderr redirect to a file, but insert the hostname (which created the error) to be listed before the error.

Instead of this entry in the log file (from host BLAH):

remshd: Login Incorrect

I would like this:

BLAH remshd: Login Incorrect

I have tried to put in the host variable before/after/between the redirect, but nothing has worked...

See if this works for you...

remsh $host -n grep -i -e "EMS" -e "error" -e "warning" -e "excessive" /var/adm/syslog/syslog.log 2>&1 | xargs  echo $host >>syslog_issue_list.txt

shamrock,

Thank you for the reply but your suggestion did not work. The error, remshd: Login Incorrect, propagated on the monitor and the hostname was written to the log file.

Through alot of trial and error, it seems the redirection will only work correctly if it is placed just after the remsh command, as it currently stands.