1820483 Members
2678 Online
109624 Solutions
New Discussion юеВ

Re: Logger Command

 
Rajkumar_3
Regular Advisor

Logger Command

Hai

I am running one script which will automatically run by using cronjob..So i need to use the LOGGER in HP-Unix command to automatically return the status of that file to SYSLOG.LOG

Can anyone help me how to use this LOGGER command...
Oracle DBA
9 REPLIES 9
Rainer von Bongartz
Honored Contributor

Re: Logger Command


/usr/bin/logger "this is a test" will produce the fpllowing entry in /var/adm/syslog/syslog.log

Oct 11 09:37:16 mars bongartz: this is a test

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Rajkumar_3
Regular Advisor

Re: Logger Command

Hai rainer Von

Thank you for your reply..

So if i include this command :
/usr/bin/logger "The test is successfull"
in my shell script ,it will automatically returns to the syslog..

How can i identify whether that script is successfull or not successfull ?? How can i check the condition in the shell script..??

Thanks for the advance in help.

Regards
Rajkumar
Oracle DBA
Robin Wakefield
Honored Contributor

Re: Logger Command

Hi,

As a quick test, type:

logger hello

This should add a line to /var/adm/syslog/syslog.log

You can control which logfile to send to using the -p switch. This will send to the logfile as configured in syslog.conf, so:

echo hello | logger -d mail.debug

will probably end up in /var/adm/syslog/mail.log because of the line:

mail.debug /var/adm/syslog/mail.log

in syslog.conf. You can also dump the contents of a file (-f), add the process id (-i), change the tag (-t).

I'd just play around with it, and keep another window open that is tailing the logfiles:

tail -f /var/adm/syslog/syslog.log (or whatever).

Also "man 1 logger".

Rgds, Robin.
Robin Wakefield
Honored Contributor

Re: Logger Command

Hi,

Within your script, check the return code of commands, e.g. to check if a file exists:

test -f /tmp/dummy
if [ $? -eq 0 ] ; then
logger "/tmp/dummy exists"
else
logger "/tmp/dummy missing"
fi

When you wish to terminate a script, use the "exit" command to set the return code. You can then test this as above, and log accordingly.

Rgds, Robin.
Rainer von Bongartz
Honored Contributor

Re: Logger Command

status of your scripts depends very much on what you are doing there.
yout script should check the return values (echo $?) of the commands.

if [[ $? != 0 ]]
then
print "cmd not OK!"
else
print "cmd ok "
fi

or something like this

Reagards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Rainer von Bongartz
Honored Contributor

Re: Logger Command

it should of course read

logger "cmd not ok" instead of
print "cmd not ok"
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Rajkumar_3
Regular Advisor

Re: Logger Command

Hai All,

I will try now with all the option that you all have given to me and let you know the results..

Thanking you

Regards
Rajkumar
Oracle DBA
Santosh Nair_1
Honored Contributor

Re: Logger Command

Also, you should be able to specify the facility and level for syslog in the logger command. So for example if you want to treat your script failures as an error condition you could do something such as:
if [[ $? != 0 ]]
then
logger -p user.err "cmd not OK!"
else
logger -p user.notice "cmd ok "
fi

-Santosh
Life is what's happening while you're busy making other plans
Rajkumar_3
Regular Advisor

Re: Logger Command

Hai,

Thank you all for the Help..

Thanks & Regards
Rajkumar
Oracle DBA