DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 13th November 2010
marbi marbi is offline
New User
 
Join Date: Nov 2010
Posts: 1
Default Bash and pfctl = problem

Hello,

I would like to write a script that is able to check if file pf.conf has any errors:

command:
pfctl -n -f pf.conf

now:
- if configuration file is OK there will be no response
- if configuration file in not OK, then some error may come up

syntax error
this one is OK, but neither way Bash can't see it, apart from that, I can't neither take it over nor save it to the file

and simple intruction:
var1=`/sbin/pfctl -n -f /etc/pf.test.conf`
if [ -z "$var1" ]; then
echo OK
else
echo not OK
fi

But each time the replay is OK, no matter if the configuration file has some errors or doesn't have any.
Therefore, does anybody have any idea how to check if the configuration file is OK and after that, how to transfer the result to Bash script?

Thank you.
Reply With Quote
  #2   (View Single Post)  
Old 13th November 2010
ohauer ohauer is offline
Port Guard
 
Join Date: May 2008
Location: germany
Posts: 32
Default

place the following lines into your ~/.bashrc and you are done

now you can type
# pftest to check if your pf.conf is OK and
# pfinstall to test and install your pf.conf

Code:
PFCONF=/etc/pf.conf

pftest(){
    pfctl -n -f ${PFCONF} &&
    echo "${PFCONF} => seems to work: $?"
}
pfinstall(){
    pfctl -n -f ${PFCONF} &&
    pfctl -f ${PFCONF} &&
    echo "${PFCONF} => seems to work: $?"
}
Reply With Quote
  #3   (View Single Post)  
Old 14th November 2010
comet--berkeley comet--berkeley is offline
Real Name: Richard
Package Pilot
 
Join Date: Apr 2009
Location: California
Posts: 163
Default

Quote:
Originally Posted by marbi View Post

var1=`/sbin/pfctl -n -f /etc/pf.test.conf`
if [ -z "$var1" ]; then
echo OK
else
echo not OK
fi
The "trick" is to use the $? variable to capture the return code from the command:

/sbin/pfctl -n -f /etc/pf.conf
rc=$?
if [ $rc -eq 0 ]; then
echo "OK"
else
echo "not OK"
fi
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pfctl anchors manipulation clarification on 4.7 sgeorge OpenBSD Security 0 2nd July 2010 05:16 AM
flush states pfctl joostvgh OpenBSD Security 3 27th January 2010 06:50 PM
Changing shell to bash rex FreeBSD General 13 29th August 2008 03:20 AM
Is bash included in OpenBSD? bsdnewbie999 OpenBSD General 21 2nd August 2008 02:57 AM
pfctl -s info counters don't change audio FreeBSD Security 2 16th July 2008 11:01 PM


All times are GMT. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick