Original Post
I have pfSense 23.01 with FreeBSD 14.0
On the command line, this works fine.
sh
sudo easyrule block lan 192.168.1.20 ; sudo easyrule block lan 192.168.1.21 ;
If I run the same command in a shell script:
#!/bin/sh
sudo easyrule block lan 192.168.1.20 ; sudo easyrule block lan 192.168.1.21 ;
It only runs the first command (.20) and completely ignores the second one (.21).
What am I doing wrong?
PS: I have tinkered with some scripts in bash on Ubuntu, but don't have any experience with FreeBSD or sh. Not sure if this is a pfSense question, or a shell script question.
Update #1
Following @shellter's advice, I tried putting the commands on separate lines in the script like this
#!/bin/sh
sudo easyrule block lan 192.168.1.20 ;
sudo easyrule block lan 192.168.1.21 ;
That worked. Now I am faced with the next problem. How do I construct a string variable by concatenating multiple strings, which eventually need to run the command. I tried the following. The below only runs the first line
command=$command" sudo easyrule block lan 192.168.1.20 ;\n"
command=$command" sudo easyrule block lan 192.168.1.21 ;"
$command
The below also runs only the first line
command=$command" sudo easyrule block lan 192.168.1.20 ;"$'\n'
command=$command" sudo easyrule block lan 192.168.1.21 ;"
$command
This one doesn't run anything.
command=$command" sudo easyrule block lan 192.168.1.20 ;"$'\n'
command=$command" sudo easyrule block lan 192.168.1.21 ;"
"$command"
PS: I could probably install bash and make this work, but Netgate / pfSense doesn't recommend it (for it potentially introduces an additional attack vector). Since this is a critical security node, I am not comfortable taking the risk - no matter how small