0

i would like to do some process, that will block some IP that stores in variables. The syntax that i wrote:

[status4,cmdeks2] = system("sudo tail -1  /var/log/apache2/access.log | cut -d ' ' -f 1");
lm = system(['sudo iptables -A INPUT -s' cmdeks ' -j DROP '])

the cmdeks 2 itself is some IP:

192.168.88.10

But it return some error, that matlab output:

/bin/bash : line 1: -j: command not found

How do i put that cmdeks in the system syntax?

1 Answer 1

1

I guess it is because cmdeks2 contains a line feed code and the iptables command breaks by the line feed code.

enter image description here

Extracting only IP address via sscanf will work.

[status4,cmdeks2] = system("tail -1  ./access.log | cut -d ' ' -f 1");
cmdeks2 = sscanf(cmdeks2, '%s\n'); % cmdeks2 contains only IP address
lm = system(['sudo iptables -A INPUT -s ' cmdeks2 ' -j DROP '])

Also, you might have extra iptables rules by your previous trials, so please delete those rules by "iptables -D" command.

Sign up to request clarification or add additional context in comments.

1 Comment

Sounds good! Also, blank space is necessary between -s and cmdeks2, so I've modified a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.