Logger command not working for one script

Hi,

On RHEL 7.2, I created below script in cronjob for every minute. If this process is found to be not running, it should record message in /var/adm/xymessages, start it and send email.

#!/bin/bash

source /export/home/prodadm/.bash_profile

if [ `ps -ef |grep ercapi | grep -v grep | wc -l` -eq 0 ];
then
        /export/home/prodadm/erc/scripts/start-erc;
        /bin/logger -p 'XY 6990 - ERC API on `hostname` is restarted' /var/adm/xymessages;
        /bin/mail -s "ERC API on v911t-vpctools restarted" test-admin@xyz123.com;
fi

But logger part is not working, seems like I am missing something. It should pick hostname also. Probably I am missing an entry in rsyslog.conf ?

Please advice.

Thanks

Did you try giving the whole pathname of hostname ?

Yes, it misses same thing

[root@test-servs ~]# logger -p 'XY 6990 - ERC API on `/bin/hostname` is restarted' /var/adm/xymessages
logger: unknown priority name: XY 6990 - ERC API on `/bin/hostname` is restarted.
[root@test-servs ~]#

The single quotes will stop command subsitution. The hostname call need to be outside of single quotes eg:

'XY 6990 - ERC API on '$(hostname)' is restarted'

or

"XY 6990 - ERC API on $(hostname) is restarted"

Yes. Second option works. Thanks

[root@test-servs ~]# logger -p "XY 6990 - ERC API on $(hostname) is restarted" /var/adm/xymessages
logger: unknown priority name: XY 6990 - ERC API on test-servs is restarted.
[root@test-servs ~]#

Script is fine now. Looks like, it is logger issue now, more appropriate for "Solaris" sub-form now :slight_smile:

You must give a facility.severity pair after -p
For ex

logger -p user.err  "XY 6990 - ERC API on $(hostname) is restarted"

The syslog service determines which file user.err is.

2 Likes

You could also create a /etc/rsyslog.conf entry to log a facility to your /var/adm/xymessages file eg:

$WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg Smiliemusrmsg:*
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log
ercapi.* $WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg Smiliemusrmsg:*
uucp,news.crit /var/log/spooler
local2.* /var/log/boot.log
local3.* /var/adm/xymessages

And then use:

# logger -p local3.info "message"
1 Like

This is even better, specific to application. But seems like, something is missing.
Am I using correct syntax ?

[root@test-servs ~]# cat /etc/rsyslog.conf | grep ercapi
ercapi.*                                                /var/adm/xymessages
[root@test-servs ~]# logger -p ercapi.info  "XY 6990 - ERC API on $(hostname) is restarted"
logger: unknown facility name: ercapi.
[root@test-servs ~]#

--- Post updated at 03:27 PM ---

local3 worked very well. Thanks you both of you.

Apologies for that, after doing some testing I discovered there are fixed supported facility names and local0 thru local7 are there for use as custom (user-defined) facilities.

1 Like
Moderator comments were removed during original forum migration.