mikrotik指挥过bash

时间:2017-09-25 11:12:54

标签: bash ssh mikrotik

我想通过bash脚本阻止一些网站。我有一个网站名称列表list.txt。路由器是mikrotik。 我需要Syntax的帮助。我不能在ssh连接后发送命令

file =“list.txt”

lines = cat $ file

sshpass -p'blabla'ssh y@x.x.x.x

表示$行中的行;做

“/ ip proxy acces add dst-host =”$ line“action = deny comment =”list“

完成

2 个答案:

答案 0 :(得分:0)

您在本地计算机中声明$ file和$ lines,您连接的路由器无法循环此值。

尝试这样的事情:

static class ListRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList chartList, Object
        value, int index, boolean isSelected, boolean cellHasFocus) {
        ChartPanel chartPanel = (ChartPanel) value;
        if (isSelected) {chartPanel.getChart().setBackgroundPaint(Color.red);}
        else {chartPanel.getChart().setBackgroundPaint(Color.white);}
        return chartPanel;
    }
}

答案 1 :(得分:0)

这是一个非常老的问题,但是如果有人遇到同样的问题,我会回答我;)

#!/bin/bash

where="<path to your mikrotik config.txt>";
len=`cat $where | wc -l`;
config=`for (( c=1; c<=$len; c++ )) do line=\`sed -n "$c""p" $where\`; echo  $line; done`;

sshpass -p "blabla" ssh -t -oStrictHostKeyChecking=no y@x.x.x.x $config

Mikrotik还支持ssh-key!使用密钥代替sshpass更加安全。