I am in the process of converting to CentOS 6.5 from 5.5 and need a way to check if sendmail is on or not. For reasons I don't want to go through, I need to be able to check if sendmail is ON as a NON root user. In CentOS 5.5, I could use
/sbin/service sendmail status running as a non root user. In CentOS 6.5, security is a bit tighter and new code was added to the
# Check that we're a privileged user [ `id -u` = 0 ] || exit 4
The sendmail script uses the following code to check it's status:
status) echo -n sendmail; status -p /var/run/sendmail.pid -l sendmail RETVAL=$? echo -n sm-client; status -p /var/run/sm-client.pid -l sm-client [ $RETVAL -eq 0 ] && RETVAL=$? ;;
In the beginning of the sendmail script the
functions library is source so
status() can be called in the
# Source function library. . /etc/rc.d/init.d/functions
As root, you would typically see this when running
/sbin/service sendmail status:
sendmail (pid 1107) is running... sm-client (pid 1115) is running...
When running as a NON root user I receive
return code 4
What I have tried so far is checking
/var/run/sendmail.pid to get the process ID, then I check to see if there is there is and entry in
/proc for the pid. For example,
As a NON root user:
cat /var/run/sendmail.pid - Get the pid 1107 /usr/sbin/sendmail -bd -q3600s
Then I check
Name: sendmail State: S (sleeping) Tgid: 1107 Pid: 1107 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 51 51 51 Utrace: 0 FDSize: 32 Groups: 51 VmPeak: 12844 kB VmSize: 12840 kB VmLck: 0 kB VmHWM: 2020 kB VmRSS: 2020 kB VmData: 1176 kB VmStk: 208 kB VmExe: 824 kB VmLib: 10156 kB VmPTE: 44 kB VmSwap: 0 kB Threads: 1 SigQ: 0/3865 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000001006 SigCgt: 0000000180016201 CapInh: 0000000000000000 CapPrm: ffffffffffffffff CapEff: ffffffffffffffff CapBnd: ffffffffffffffff Cpus_allowed: 1 Cpus_allowed_list: 0 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 560 nonvoluntary_ctxt_switches: 2
/proc/<pid> doesn't exist, I know the service is not on.. This method seems to work, but I don't trust it completely and would rather use
/sbin/service sendmail status.
Any ideas on the best way to check if sendmail service is running as a NON root user??