在linux上执行.sh文件出错 Try `iptables -h' or 'iptables --help' for more information.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在linux上执行.sh文件出错 Try `iptables -h' or 'iptables --help' for more information.相关的知识,希望对你有一定的参考价值。

在linux上执行.sh文件:(部分内容如下)
echo " -->[*] Setting iptables rules"sudo iptables -Fsudo iptables -t nat -Fsudo iptables -t nat -A POSTROUTING -s $subnet.0/24 -o $out_interface -j MASQUERADEsudo iptables -A FORWARD -s $subnet.0/24 -o $out_interface -j ACCEPTsudo iptables -A FORWARD -d $subnet.0/24 -m conntrack --ctstate

执行出现错误iptables v1.4.12: host/network `.9.0' not foundTry `iptables -h' or 'iptables --help' for more information.iptables v1.4.12: host/network `.9.0' not foundTry `iptables -h' or 'iptables --help' for more information.iptables v1.4.12: host/network `.9.0' not foundTry `iptables -h' or 'iptables --help' for more information.

参考技术A 脚本在执行时出错,从错误来看,是$subnet变量的赋值有问题,host/network 需要根据具体情况填写 参考技术B 应该是你变量有问题
你在脚本里面
每一句ipdatbles之前
echo 下变量 检查下是否正确本回答被提问者采纳

ubuntu 下执行shell脚本的问题

将一个脚本保存为带有扩展名的文件,如test.sh,在终端上输入: chmod +x test.sh然后输入: test.sh终端显示: test.sh 找不到命令 但是,如果在终端上输入: ./test.sh就能运行成功。另外,如果脚本文件没有扩展名的话,在终端上输入: ./test 或者 test脚本都能执行成功,这是为什么呢? 当然,如果不想输入chmod那一行命令的话,也可以直接执行,直接在终端上输入:/bin/sh test或者/bin/sh test.sh

参考技术A 诶!你还要去好好去玩一下Linux(不要用图形系统),你问的这些问题,真不好解释
1,chmod +x test.sh:将test.sh变成可执行权限。
2,test.sh 第一行有"#!/bin/sh” 告诉解释器在什么位置。
3,第一步test.sh变成可执行了,./test.sh(运行当前目录下一个可执行文件,这是一个shell脚本,需要解释器,如果有"#!/bin/sh”通过sh解释,如果没有会报错没这个命令)。
4,./test.sh(第三步我以解释什么意思);运行test.sh(将同过path路径去找这个命令,显然这个tesh.sh这个文件不在你path路径下,你怎么能运行呢)。
5,sh test.sh(sh在/bin目录下也就是已经假如path路径,用sh命令解释你这个脚本)本回答被提问者和网友采纳
参考技术B export PATH=.:$PATH

add . to system PATH variable, so system will search command starting from current directory.

You can also add the "export" line to $HOME/.bashrc, so it works always...

以上是关于在linux上执行.sh文件出错 Try `iptables -h' or 'iptables --help' for more information.的主要内容,如果未能解决你的问题,请参考以下文章

2018-03-22 Linux学习

linux怎么远程执行另一台linux机器上的shell文件?

windows编写sh脚本在linux上不能执行——command not found

linux 做了个备份脚本 .sh的,用命令sh bf.sh可以执行,如何放到桌面上双击运行,并看到执行过程,非常感谢!

windows系统下编写的sh拷贝到ubuntu后执行出错:/usr/bin/env: ‘bash ’: No such file or directory

在Windows下生成的shell文件在上传到Linux上发现无法执行