1
16.7 Legacy Series / Re: OPNSense CLI interface on Roadmap?
« on: October 27, 2017, 02:21:06 pm »Quote
And one last question:
Is there a way to check whether ports are down/up and/or whether services are running/stopped through CLI, API or other?
if you just want to know if it's working Plugged or unplugged,
I did it, simply using shell command with regex. It's maybe not the best way to do it, but for now it work. And that's the best I can do.
I just started Linux a few days ago and i'm not a computer scientist neither a native english speaker, you have probably noticed that.
For exemple :
Code: [Select]
ifconfig igb2 | sed -n 's/.*status: \([^ ]*\).*/\1/gp'
Will result as : "Active" or if not active "no"
For the services i've seen that a file with extension .pid was created when a services is running.
Code: [Select]
#!/bin/sh
isvalidpid()
{
/bin/pgrep -nF $1
}
is_process_running()
{
/bin/pgrep -anx
}
if [ $(isvalidpid /var/run/ntpd.pid) > 1 ] && [ $(is_process_running) > 1 ]
then
echo "Active"
else
echo "Not"
fi