What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Why is this in my firewall-start script!? logger -t $(basename $0) $1

  • Thread starter Thread starter Deleted member 27741
  • Start date Start date
D

Deleted member 27741

Guest
I added a few iptables rules yesterday, they did not work. Turns out, I had the command-

logger -t $(basename $0) $1

at the top of my firewall-start script. Of course, that kept the other rules from running because apparently that command hangs. I can't remember for the life of my why I would put that command in firewall-start. Does anyone know why it would be there? Does it look like a snippit of any script you know of, because I did not write the code!
 
Last edited by a moderator:
I added a few iptables rules yesterday, they did not work. Turns out, I had the command-

logger -t $(basename $0) $1

at the top of my firewall-start script. Of course, that kept the other rules from running because apparently that command hangs. I can't remember for the life of my why I would put that command in firewall-start. Does anyone know why it would be there? Does it look like a snippit of any script you know of, because I did not write the code!

A lot of people use that, or similar, to write a syslog entry for executing the script
$(basename $0) = the name of the script
$1 = passed parameter

It shouldn't hang, just write to the syslog...

Re your script not running....how did you edit it? Are you sure you didn't introduce DOS CR-LF sequences when you added the lines? Since you are running my fork, you can run 'dos2unix' to fix it up....
dos2unix /jffs/scripts/firewall-start
 
Last edited:
logger -t $(basename $0) $1
There is a "gotcha" with that command (that keeps tripping me up).

If you're running it from the command line (i.e. for testing) then you must supply a parameter for $1. If you don't then the logger command will hang waiting for input.

Maybe I should change it to:
Code:
logger -t $(basename $0) ${1:-missing}
or is that just getting overly complicated? :)
 
Last edited:
Looks like it works like this-
logger -t $(basename $0) $

Take out the 1 out and it is all good, writes to syslog and runs without hanging. Thanks, guys!


********************Edit*******************
Changed it to this-
logger -t $(basename $0) THIS SCRIPT HAS RUN

In the log it looks like this-
firewall-start: THIS SCRIPT HAS RUN

I guess it was the 1 that was the problem, leaving just the $ looked odd in the log so I changed it to something more descriptive.

Now I am kicking myself in the head for not having my firewall-start running correctly for months now. Guess I should have actually LOOKED at iptables to make sure the script was run. Live and learn. ;)
 
Last edited by a moderator:
Well the purpose of the "$1" was so that you could see what the value of the parameter was in the syslog. If you change it to "$" then it's meaningless. You might as well put something a bit more user friendly there:
Code:
logger -t $(basename $0) Starting
 
If someone knows how to get the command working with the paramater value, that would be cool!
 
Thinking about it a bit more the answer is obvious. Use something like this:
Code:
logger -t $(basename $0) $1 "Starting"
That way the logger command will always have something to print even if the user forgets to supply a value for $1.
 
Or something like this....
Code:
logger -t $(basename $0) "Starting, Parameter: $1"
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Back
Top