AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-330859

Piduna Valeriu's questions

Martin Hope
Piduna Valeriu
Asked: 2016-11-16 06:29:07 +0800 CST

bash 中的脚本不能正常工作

  • 0

我需要按数字获取接口。我的脚本:

#!/bin/bash

interfaces=/root/tt
interfaces_with_numbers=/root/tt2

ls -1 /sys/class/net > /root/tt
cat -n $interfaces > $interfaces_with_numbers
cat $interfaces_with_numbers

read number
echo $number

eth=`cat $interfaces_with_numbers | grep $number | awk '{ print $2 }'`

if [[ -d /sys/class/net/$eth ]];then
    echo "You choose is: $eth"
else
    echo "not found"
fi

我有输出:

 1  dummy0
 2  eno1
 3  enp4s0
 4  lo
 5  virbr0
 6  virbr0-nic

它只是带有空格的文本文件。好的。脚本问,我想输入什么。我输入了“2”。它正在工作 - 结果,我得到了接口的名称。我输入了“1”,但我“未找到”。我在linux命令行中写过:

cat tt2 | grep 1 | awk '{ print $2 }'

我得到了输出:

dummy0
eno1

如何正确执行此脚本?请帮忙。谢谢你的关注。

linux scripting bash shell
  • 2 个回答
  • 91 Views
Martin Hope
Piduna Valeriu
Asked: 2016-10-13 01:41:30 +0800 CST

Bash 脚本,从文件中读取,增加变量并输出到其他文件

  • 0

我有一个带有许多 VLAN 的 Debian 服务器。所有这些vlan都从1开始。我需要从文件中读取所有IP,并将所有这些输出到其他文件中。一切都好,但我对增量变量有疑问。

if [ -f /root/ip ]; then
 for IP_ADD in `grep -v ^# /root/ip`; do
eth=1
eth=`expr $eth + 1`
 cat >> "/root/inter" <<END
auto eth0:$eth
iface eth0:$eth inet static
      address $IP_ADD
      netmask 255.255.255.0
END
  done
fi

运行此脚本后,我在文件“inter”中输出:

auto eth0:2
iface eth0:2 inet static
      address 192.168.110.1
      netmask 255.255.255.0
auto eth0:2
iface eth0:2 inet static
      address 192.168.109.1
      netmask 255.255.255.0
auto eth0:2
iface eth0:2 inet static
      address 192.168.108.1
      netmask 255.255.255.0
auto eth0:2
iface eth0:2 inet static
      address 192.168.107.1
      netmask 255.255.255.0

我的变量 eth 增加了,但只有一次。我哪里有错误?请帮忙。

linux bash shell autoincrement shell-scripting
  • 1 个回答
  • 1022 Views
Martin Hope
Piduna Valeriu
Asked: 2016-10-13 00:23:01 +0800 CST

Bash脚本,从文件读取并写入其他文件

  • 1

我有一个名为 3proxy 的代理服务器。我需要像这样添加ip:

 flush
 auth iponly strong
 deny * * * 25,2525 * * *
 allow test
 proxy -n -a -i192.168.110.1 -e192.168.110.1 -p65233
 socks -n -a -i192.168.110.1 -e192.168.110.1 -p65234

这是一个配置 3proxy 的块。我需要在 3proxy 中添加更多 100 个具有不同 ip 的配置 3proxy 块。我写脚本:

if [ -f /root/ip ]; then
 for IP_IN_NGINX in `grep -v ^# /root/ip`; do
 cat > "/root/3proxy" <<END
 flush
 auth iponly strong
 deny * * * 25,2525 * * *
 allow test
 proxy -n -a -i$IP_IN_NGINX -e$IP_IN_NGINX -p65233
 socks -n -a -i$IP_IN_NGINX -e$IP_IN_NGINX -p65234
END
  done
fi

在 /root/ip 中,我有一个 IP 块。在 /root/3proxy 我想用不同的 IP 编写许多配置块。当我启动脚本时,我在输出文件中有一个配置 3proxy 块和一个 IP。但是我需要许多配置块,这些配置块与我的文件中的 IP 不同。我哪里有错误?请帮忙。

linux bash proxy shell shell-scripting
  • 1 个回答
  • 140 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve