Ash scripting "not found" error

Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions
Author Message
DizKiz
DD-WRT Novice


Joined: 19 Oct 2015
Posts: 2

PostPosted: Mon Oct 19, 2015 2:35    Post subject: Ash scripting "not found" error Reply with quote
I'm writing a script that will enable and disable internet access (on a timed basis) specific IP addresses on my internal network. The list of IPTABLES commands comes in as a "~" delimited list and my code loops through them and executes them in sequence.

The problem I'm having is that when the script goes to execute the command, a "not found" error is returned but when I copy and paste the command into the command line while telnet[ed] on router, the command works.

Script (loop):

Code:

fw_cmd_res="/usr/sbin/iptables -D FORWARD -s 192.168.69.112 -j DROP~/usr/sbin/iptables -D FORWARD -s 192.168.69.113 -j DROP"
IFS="~"
for cmd in $fw_cmd_res
do
  echo "cmd: $cmd"
  fw_cmd_res=$($cmd)
done


Results (with error):
Code:
cmd: /usr/sbin/iptables -D FORWARD -s 192.168.69.112 -j DROP
./requestor: line 61: /usr/sbin/iptables -D FORWARD -s 192.168.69.112 -j DROP: not found



I've even tried to write code as follows (to rule out an issue in the loop and the data passed):

Code:
test1="/usr/sbin/iptables -D FORWARD -s 192.168.69.112 -j DROP"
echo "cmd: $test1"
fw_cmd_res=$($test1)


And I still get the same result. A "which" on iptables shows the path to the executable exists /usr/sbin/iptables thus is correct.

Here are my system details:
Code:

DD-WRT v3.0-r27365M (06/18/15) kongac
Running on a Netgear Nighthawk R6700

root@r0ut3r:/jffs/webControl# uname -a
Linux r0ut3r 3.10.80 #389 SMP Thu Jun 18 22:32:27 CEST 2015 armv7l GNU/Linux
root@r0ut3r:/jffs/webControl# sh --version
BusyBox v1.23.2 (2015-06-18 22:31:17 CEST) built-in shell (ash)


Any help would be excellent. I bet it's a simple ash-related syntax issue, but I'm stumped. Please help.
Sponsor
DizKiz
DD-WRT Novice


Joined: 19 Oct 2015
Posts: 2

PostPosted: Wed Oct 28, 2015 0:41    Post subject: Update: a hack of a solution but it appears to work Reply with quote
So... since I seemed to have stumped everyone I had to channel the power of dump luck. This is a complete 100% hack that I really believe I lucked into...

So... executing the command directly in the script was giving me a "not found". So... I "echo"ed it out to am executable script file on the file system in the same folder. Then I did an "sh" on that file using the full path and it worked. Seems dumb, but it work.

Really the fix leads me to believe I just have some sort of syntax error, but I'm not 1337 enough to know what it is. Please post a real fix if you find one.



Code:


IFS="~"
for cmd in $fw_cmd_res
do
  echo "cmd: $cmd"
  fw_cmd_res=$(echo "$cmd" > /jffs/webControl/cmd)
  fw_cmd_res=$(sh /jffs/webControl/cmd)
done
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum