List of services on Centos and corresponding packages.
Hi All,
I am using below script to get a list of all running services on my Centos box, corresponding package name and the install location.
for i in $(service --status-all | grep -E running\|stopped\|"not running" | awk '{print $1}');
do
echo "Service $i" >> $HOME/MyLog/running_$HOSTNAME.log;
rpm -qf /etc/init.d/$i >> $HOME/MyLog/running_$HOSTNAME.log;
rpm -ql $(rpm -qf /etc/init.d/$i) >> HOME/MyLog/running_$HOSTNAME.log;
done
This code snippet has a few problems. Though it lists all services, packages and install location in output log, I am not sure if the installed location given by rpm -ql is quite correct. It shows a lots of instal locations or files. I would need just the install location of the base package.
Also, if a service name if not found in /etc/init.d, the script throws a console output as well, which I dont want. Is there a way in a script where I can avoid the console output and errors? Anything which I can include in script for this?
Please revert if anyone has any clue on this.
Thanks.
Regards.
|