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 ?
[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 ~]#
[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
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.