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-1159881

Cas's questions

Martin Hope
Cas
Asked: 2022-06-07 03:06:35 +0800 CST

为主机和虚拟机设置网桥

  • 0

我在为我的主机和我的虚拟机设置网桥时遇到了很多问题。

主机(服务器的操作系统)是 Ubuntu 20.04.4 LTS。VM(使用 KVM 和 virt-manager)是 TrueNAS Core (FreeBSD)。我的服务器(主板上)有一个以太网端口,我想同时用于我的操作系统和虚拟机。os 需要获取 192.168.2.15 的 ip,dns 设置为 1.1.1.1,vm 需要获取 192.168.2.16 的 ip。它们都需要从“外部”访问。所以,据我了解,我需要设置一个网桥。

好吧,这一切都出错了。我从这个视频开始,但没有成功。然后我尝试了这个视频,但也没有成功。然后我尝试了本指南,但再次没有成功。然后我转向 SO 并尝试了这些(1、2),但都没有成功。

每次都出事。大多数时候 DNS 不工作,或者 IP 地址混乱(完全不同的子网),或者操作系统具有正确的 IP 但无法 ping 任何其他设备(不是 1.1.1.1,也不是 192.168.2.79,即我的静态 ip-ed win10 计算机)或 /etc/network/interfaces 被忽略(该文件还不存在)。大多数时候人们建议使用sudo /etc/init.d/networking restartsystemd 或类似使用 systemd,但每次我收到networking不存在的消息时,我觉得这很奇怪,因为其他人都拥有它。

这只是一团糟,我无法让它工作。我真的很感激一些帮助!

该文件/etc/network/interfaces当前不存在。 ifconfig -a输出:

enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.15  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::8506:f97f:df7c:f66b  prefixlen 64  scopeid 0x20<link>
        ether 18:c0:4d:9b:3c:12  txqueuelen 1000  (Ethernet)
        RX packets 10390  bytes 3524106 (3.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2534  bytes 330756 (330.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xfc600000-fc61ffff  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 7172  bytes 712208 (712.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7172  bytes 712208 (712.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:06:8d:b0  txqueuelen 1000  (Ethernet)
        RX packets 142  bytes 12152 (12.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 4136 (4.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:06:8d:b0  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fee6:a823  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:e6:a8:23  txqueuelen 1000  (Ethernet)
        RX packets 142  bytes 14140 (14.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 939  bytes 55015 (55.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

编辑:里面/etc/netplan,有一个文件:01-network-manager-all.yaml. 内容:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

我不关心网络管理员。如果有一些解决方案有效但破坏了网络管理器,我完全可以接受。

networking
  • 1 个回答
  • 597 Views
Martin Hope
Cas
Asked: 2021-08-04 05:35:08 +0800 CST

如果它们在文件中紧随其后,如何仅删除重复的行

  • 3

假设我有以下文件:

$ cat test.txt
a
-----
b
-----
-----
c
-----
-----
-----
d
-----
e
-----
-----

现在我想删除所有的-----,但前提是它们彼此重复。所以结果应该是这样的:

a
-----
b
-----
c
-----
d
-----
e
-----

我试过grep -Pvz -- "-----\n-----"了,但是没有用。

command-line
  • 2 个回答
  • 593 Views
Martin Hope
Cas
Asked: 2021-06-30 07:33:48 +0800 CST

如何杀死在后台运行的脚本,但仅在使用某个标志运行时获取脚本的PID

  • 0

我可以在后台运行多个 bash 脚本实例,一切都很好。我以这样的方式设置它,有些有-x作为标志,有些没有。看:

./test.sh &
./test.sh &
./test.sh -x &
./test.sh -x &

现在,我想杀死所有使用该-x标志运行的脚本。我总是用这个杀死在后台运行的脚本:

ps -aux | grep -Po "^\S{1,}\s*\K\d*(?=.*test.sh$)" | \
while read -r level
do
   kill $level
done

但是,ps -aux不显示脚本运行时给出的任何参数/标志。因此,当使用它时,我不能只抓取使用-x. 有针对这个的解决方法吗?我只想杀死使用-x.

command-line
  • 2 个回答
  • 1203 Views
Martin Hope
Cas
Asked: 2021-06-28 03:34:17 +0800 CST

在 perl 正则表达式中使用 ?!<string> 时,bash 将其解释为搜索命令历史

  • 0

简单的问题,但我无法解决。

我有以下 perl 正则表达式:

echo ... | grep -P "(?i)(v(ersion)?)\s?(?!0)\d(\.|,)\d{1,}"

这应该匹配每个描述某事物版本的字符串(例如V2,0or version 1.2)。但是当版本以V0.... 但是,当我执行此操作时,会出现错误-bash: !0: event not found,因为!<string>用于搜索命令历史记录并执行最新命中。

这基本上打破了我的 perl 正则表达式。如何避免 shell 将其解释为快捷方式?

command-line
  • 1 个回答
  • 51 Views
Martin Hope
Cas
Asked: 2021-06-21 12:10:34 +0800 CST

在 curl 请求后管道 grep 时,正则表达式的工作方式非常奇怪

  • 0

简单的问题,但真的很奇怪。

当我发出 curl 请求并执行... | grep -Po "^\d+$"时,即使有 400 多个结果应该匹配,它也不会返回任何内容。见下文:

#example snippet of curl output
107
00:15:54,936 --> 00:15:56,646
Yeah, this is him.
We got him.

108
00:16:07,823 --> 00:16:11,869
So, how long
you been in South Florida?

109
00:16:11,953 --> 00:16:13,871
A while.
Before that?

110
00:16:17,166 --> 00:16:20,253
We know you're Brian O'Conner,
formerly of the LAPD.

111
00:16:21,128 --> 00:16:23,214
- You got the wrong guy.
- Really?

112
00:16:28,177 --> 00:16:29,929
How you doing, O'Conner?

所以这是 curl 输出的一部分。在这种情况下,完整的输出达到 1000+(此处为 107-112)。现在:

$ [curl request] | grep -Po "^\d+$"
[empty response]

$ [curl request] | grep -Po "^\d+"
[shit ton of results]

我真的不明白。我也尝试添加-a到 grep ,但这也没有帮助。

为什么 $ 不起作用?还有一个更好的问题:为什么它会使每次点击都无效(也就是没有匹配项)?

编辑:上面 curl 片段的 xxd 输出

00000000: 3130 370d 0a30 303a 3135 3a35 342c 3933  107..00:15:54,93
00000010: 3620 2d2d 3e20 3030 3a31 353a 3536 2c36  6 --> 00:15:56,6
00000020: 3436 0d0a 5965 6168 2c20 7468 6973 2069  46..Yeah, this i
00000030: 7320 6869 6d2e 0d0a 5765 2067 6f74 2068  s him...We got h
00000040: 696d 2e0d 0a0d 0a31 3038 0d0a 3030 3a31  im.....108..00:1
00000050: 363a 3037 2c38 3233 202d 2d3e 2030 303a  6:07,823 --> 00:
00000060: 3136 3a31 312c 3836 390d 0a53 6f2c 2068  16:11,869..So, h
00000070: 6f77 206c 6f6e 670d 0a79 6f75 2062 6565  ow long..you bee
00000080: 6e20 696e 2053 6f75 7468 2046 6c6f 7269  n in South Flori
00000090: 6461 3f0d 0a0d 0a31 3039 0d0a 3030 3a31  da?....109..00:1
000000a0: 363a 3131 2c39 3533 202d 2d3e 2030 303a  6:11,953 --> 00:       
000000b0: 3136 3a31 332c 3837 310d 0a41 2077 6869  16:13,871..A whi
000000c0: 6c65 2e0d 0a42 6566 6f72 6520 7468 6174  le...Before that
000000d0: 3f0d 0a0d 0a31 3130 0d0a 3030 3a31 363a  ?....110..00:16:
000000e0: 3137 2c31 3636 202d 2d3e 2030 303a 3136  17,166 --> 00:16       
000000f0: 3a32 302c 3235 330d 0a57 6520 6b6e 6f77  :20,253..We know
00000100: 2079 6f75 2772 6520 4272 6961 6e20 4f27   you're Brian O'
00000110: 436f 6e6e 6572 2c0d 0a66 6f72 6d65 726c  Conner,..formerl
00000120: 7920 6f66 2074 6865 204c 4150 442e 0d0a  y of the LAPD...
00000130: 0d0a 3131 310d 0a30 303a 3136 3a32 312c  ..111..00:16:21,
00000140: 3132 3820 2d2d 3e20 3030 3a31 363a 3233  128 --> 00:16:23
00000150: 2c32 3134 0d0a 2d20 596f 7520 676f 7420  ,214..- You got
00000160: 7468 6520 7772 6f6e 6720 6775 792e 0d0a  the wrong guy...
00000170: 2d20 5265 616c 6c79 3f0d 0a0d 0a31 3132  - Really?....112
00000180: 0d0a 3030 3a31 363a 3238 2c31 3737 202d  ..00:16:28,177 -
00000190: 2d3e 2030 303a 3136 3a32 392c 3932 390d  -> 00:16:29,929.
000001a0: 0a48 6f77 2079 6f75 2064 6f69 6e67 2c20  .How you doing,
000001b0: 4f27 436f 6e6e 6572 3f0d 0a              O'Conner?..
command-line
  • 1 个回答
  • 875 Views
Martin Hope
Cas
Asked: 2021-05-09 02:41:50 +0800 CST

如何获取 json 输出的键和值并使用它们创建新的有效 json?

  • -1

我可以向 sonarr api 发出请求,它将给我以下输出:

curl -sL "http://192.168.2.15:8005/api/series/lookup?term=tvdb:81189&apikey=[[REMOVED]]" | jq .[]
{
  "title": "Breaking Bad",
  "sortTitle": "breaking bad",
  "seasonCount": 5,
  "status": "ended",
  "overview": "When Walter White, a chemistry teacher, is diagnosed with Stage III cancer and given a prognosis of two years left to live, he chooses to enter a dangerous world of drugs and crime with the intent to secure his family's financial security.",
  "network": "Netflix",
  "airTime": "21:00",
  "images": [
    {
      "coverType": "banner",
      "url": "https://artworks.thetvdb.com/banners/graphical/81189-g21.jpg"
    },
    {
      "coverType": "poster",
      "url": "https://artworks.thetvdb.com/banners/posters/81189-10.jpg"
    },
    {
      "coverType": "fanart",
      "url": "https://artworks.thetvdb.com/banners/fanart/original/81189-21.jpg"
    }
  ],
  "remotePoster": "https://artworks.thetvdb.com/banners/posters/81189-10.jpg",
  "seasons": [
    {
      "seasonNumber": 0,
      "monitored": false
    },
    {
      "seasonNumber": 1,
      "monitored": true
    },
    {
      "seasonNumber": 2,
      "monitored": true
    },
    {
      "seasonNumber": 3,
      "monitored": true
    },
    {
      "seasonNumber": 4,
      "monitored": true
    },
    {
      "seasonNumber": 5,
      "monitored": true
    }
  ],
  "year": 2008,
  "profileId": 0,
  "languageProfileId": 0,
  "seasonFolder": false,
  "monitored": true,
  "useSceneNumbering": false,
  "runtime": 47,
  "tvdbId": 81189,
  "tvRageId": 18164,
  "tvMazeId": 169,
  "firstAired": "2008-01-20T00:00:00Z",
  "seriesType": "standard",
  "cleanTitle": "breakingbad",
  "imdbId": "tt0903747",
  "titleSlug": "breaking-bad",
  "certification": "TV-MA",
  "genres": [
    "Crime",
    "Drama",
    "Suspense",
    "Thriller"
  ],
  "tags": [],
  "added": "0001-01-01T00:00:00Z",
  "ratings": {
    "votes": 31714,
    "value": 9.4
  },
  "qualityProfileId": 0
}

我想从该输出中获取键和值,并用它们创建一个新的有效 json 输出。这些是需要在新输出中的键(+ 值):

  1. title
  2. profileId
  3. tvdbId
  4. titleSlug
  5. images(及其所有内容和子项)
  6. seasons(及其所有内容和子项)

对于一个键,值需要更改。新值存储在一个变量中:

  1. profileId(变量$profile_id)

需要将一些东西添加到新输出中(不在 api 的输出中):

  1. "rootFolderPath": ".....",(键的值存储在变量中$root_folder_path)
"addOptions":
{
  "ignoreEpisodesWithFiles": false,
  "ignoreEpisodesWithoutFiles": false,
  "searchForMissingEpisodes": false
}

结果(以上面的示例输出为例)应如下所示:

{
  "title": "Breaking Bad",
  "rootFolderPath": "/home/cas/plex-media/series",
  "profileId": 1,
  "tvdbId": 81189,
  "titleSlug": "breaking-bad",
  "images": [
    {
      "coverType": "banner",
      "url": "https://artworks.thetvdb.com/banners/graphical/81189-g21.jpg"
    },
    {
      "coverType": "poster",
      "url": "https://artworks.thetvdb.com/banners/posters/81189-10.jpg"
    },
    {
      "coverType": "fanart",
      "url": "https://artworks.thetvdb.com/banners/fanart/original/81189-21.jpg"
    }
  ],
  "seasons": [
    {
      "seasonNumber": 0,
      "monitored": false
    },
    {
      "seasonNumber": 1,
      "monitored": true
    },
    {
      "seasonNumber": 2,
      "monitored": true
    },
    {
      "seasonNumber": 3,
      "monitored": true
    },
    {
      "seasonNumber": 4,
      "monitored": true
    },
    {
      "seasonNumber": 5,
      "monitored": true
    }
  ],
  "addOptions":
  {
    "ignoreEpisodesWithFiles": false,
    "ignoreEpisodesWithoutFiles": false,
    "searchForMissingEpisodes": false
  }
}

我强烈希望它能够在不保存到文件的情况下工作。所以它可以是一小段 bash 代码或单线/长管道,只要它不涉及保存到文件或其他东西。例如,只需完成所有需要完成的工作并将新输出保护在变量中。

command-line
  • 1 个回答
  • 582 Views
Martin Hope
Cas
Asked: 2021-04-23 03:12:57 +0800 CST

删除文件中的文本块(保存在变量中)

  • 0

这听起来像是一个在谷歌上会被多次回答的问题,而且确实如此。但奇怪的是,我找不到任何真正有效的答案(我对此有点惊讶)!

假设我有一个包含某些内容的文本文件,以及脚本中的一个变量,该变量具有需要从文件中删除的确切信息。而已。

变量的大部分值都被删除了(因为它们是 api 令牌或类似的东西)这是文本文件 ( advancedplexapivar.txt):

[Aimee]
filelocation=""
datesetup=""
checkdeluge="false"
showtoken="true"
autobackup="false"
logging="true"
logfolder=""
plexapitoken=""
ipplexserver="192.168.2.15"
sonarrapitoken=""
ipsonarrserver="192.168.2.15"
sonarrport="8005"

[Dee]
filelocation=""
datesetup="dd-mm-yyyy"
checkdeluge="false"
showtoken="true"
autobackup="false"
logging="true"
logfolder=""
plexapitoken=""
ipplexserver="192.168.2.15"
sonarrapitoken=""
ipsonarrserver="192.168.2.15"
sonarrport="8005"

在脚本中,我将一个变量设置为需要删除的内容:

oldvalue=$(very long command)

的值示例$oldvalue:

echo $oldvalue ->
[Dee]
filelocation=""
datesetup="dd-mm-yyyy"
checkdeluge="false"
showtoken="true"
autobackup="false"
logging="true"
logfolder=""
plexapitoken=""
ipplexserver="192.168.2.15"
sonarrapitoken=""
ipsonarrserver="192.168.2.15"
sonarrport="8005"

我的计划是执行以下操作,但由于多行,这不起作用:

sed -i "s/$oldvalue//g" advancedplexapivar.txt ->
unterminated s

尽管这听起来很容易(并且应该如此),但我在任何地方都找不到答案。我有一个文本文件和一个变量,其中包含我想要删除的内容。但我不知道如何使用它来使用变量的值从文件中删除文本。


这有效:

perl -i -00pe 'BEGIN{$pat = shift}; s/\Q$pat\E//' "$oldvalue" advancedplexapivar.txt

我对 Steeldriver 的问题:

  1. 如果你不想,没关系,但如果你有时间,你能解释一下命令吗?
  2. 我现在遇到不同用户之间的差距([...]),有时他们之间有 2 或 3 个空行。有没有类似的命令sed -E "s|\n{2,}|\n|g"?我当然试过了,但是没有用。
[Aimee]
...
sonarrport="8005"



[Dee]
...
sonarrport="8005"

需要成为

[Aimee]
...
sonarrport="8005"

[Dee]
...
sonarrport="8005"

允许该命令对完整文件产生影响,因此在完整文件中,“允许”时只有一个空行。

command-line
  • 2 个回答
  • 123 Views
Martin Hope
Cas
Asked: 2021-03-28 05:00:38 +0800 CST

如何使用 getopts 不接受任何内容、一个标志、一个带参数的标志和一个带两个参数的标志

  • 1

我目前通过以下方式设置 getopts:

while getopts ":p:s:d:g:i:h:" opt; do
        case ${opt} in
            p )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose plex from the command line with the argument $OPTARG" >> $logfolder/advancedplexapi.log
                fi
                selection="plex"
                argument=true
                optarg="$OPTARG"
                ;;

            s )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose sonarr from the command line with the argument $OPTARG" >> $logfolder/advancedplexapi.log
                fi
                selection="sonarr"
                argument=true
                optarg="$OPTARG"
                ;;

            d )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose deluge from the command line with the argument $OPTARG" >> $logfolder/advancedplexapi.log
                fi
                selection="deluge"
                argument=true
                optarg="$OPTARG"
                ;;

            g )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose ip geolocation from the command line with the argument $OPTARG" >> $logfolder/advancedplexapi.log
                fi
                selection="ip geolocation"
                argument=true
                optarg="$OPTARG"
                ;;

            i )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose the info page from the command line but supplied an argument" >> $logfolder/advancedplexapi.log
                fi
                selection="info"
                argument=true
                optarg="$OPTARG"
                ;;

            h )
                if [[ $logging = true ]]
                then
                    echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose help page for flags from the command line but supplied an argument" >> $logfolder/advancedplexapi.log
                fi
                echo "The help flag doesn't support an argument"
                usage | column -t -s "|"
                exit
                ;;

            : )
                case "$OPTARG" in
                    p )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose plex from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        selection="plex"
                        ;;

                    s )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose sonarr from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        selection="sonarr"
                        ;;

                    d )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose deluge from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        selection="deluge"
                        ;;

                    g )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose ip geolocation from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        selection="ip geolocation"
                        ;;

                    i )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose the info page from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        selection="info"
                        ;;

                    h )
                        if [[ $logging = true ]]
                        then
                            echo "$(date '+%d/%m/%Y %H:%M:%S') |     info      | user chose help page for flags from the command line" >> $logfolder/advancedplexapi.log
                        fi
                        usage | column -t -s "|"
                        exit
                        ;;
                esac
                ;;

            \? )
                echo "Invalid usage"
                usage | column -t -s "|"
                exit
                ;;
        esac
    done 2>/dev/null
    shift $((OPTIND -1))

此代码接受以下内容:

./script.sh                #-> just run the script without any variables set
./script.sh -p             #-> selection=plex
./script.sh -s series      #-> selection=sonarr & argument=true & optarg=series
./script.sh -h info        #-> error because -h flag doens't support arguments

#script can be run barebones (./script.sh)
#script can be run with a flag (only one allowed: -p|-s|-d|-g|-i|-h) (./script.sh -p)
#script can be run with a flag and an argument (argument only allowed when using: -p|-s|-d|-g|-i)(./script.sh -s series) (./script.sh -h info -> not allowed)

我的问题:

我需要调整代码以接受第二个参数,但我真的不知道如何:

My goal is:
./script.sh -p history list
=
selection=plex
argument=true
optarg=history
second_argument=true
second_optarg=list

./script.sh -p sessions
=
selection=plex
argument=true
optarg=sessions
second_argument=false
second_optarg=
  • -p -s 和 -d 允许使用第二个参数。
  • 如果另一个标志与两个参数一起使用(一个只允许零个或一个参数的标志),运行echo "The help flag doesn't support an second argument" && usage | column -t -s "|"
  • 当没有给出第二个参数时,second_optarg 需要为空字节
  • 当没有给出第二个参数时,需要将 second_argument 设置为 false
  • 第二个参数(当然只适用于 -p -s 和 -d)不是必需的,它是可选的
command-line
  • 1 个回答
  • 581 Views
Martin Hope
Cas
Asked: 2021-03-13 05:59:11 +0800 CST

无论我怎么努力,Deluge 都会出现问题

  • 1

我最初想在 Deluge 论坛上发布这个。问题是要注册一个帐户,您必须回答一个我真的不知道答案的问题: 洪水论坛上的问题

但是现在的问题:

  1. 当我这样做时deluge-console cache(但它可以是一切,而不仅仅是缓存),它每次都会给出以下错误:

    Could not connect to daemon: 127.0.0.1:58846
      Password does not match
    

    做的时候sudo -u deluge deluge-console cache,它确实有效,但我不想那样做。我不想使用 sudo 并与某个用户一起运行它。我只是想做deluge-console cache,它应该工作。

  2. 向 发出任何请求时deluge-console,它总是给出以下错误(在问题 1 中描述的错误之上):

     Unable to initialize gettext/locale!
    'ngettext'
     Traceback (most recent call last):
       File "/usr/lib/python3/dist-packages/deluge/i18n/util.py", line 118, in setup_translation
          builtins.__dict__['_n'] = builtins.__dict__['ngettext']
    KeyError: 'ngettext'
    
  3. 每次重新启动deluged时,我都会在 webui 中收到以下消息: 连接管理器

    我以前从未见过这种情况。

  4. 执行sudo systemctl status deluged.service deluge-web.service显示以下错误:

    mrt 12 14:50:28 Waveserver deluged[20344]: builtins.TypeError: findCaller() takes from 1 to 2 positional arguments but 3 were given
    
  5. 在 webui 中,它在底部的栏中显示以下内容: webui酒吧

  6. Sonarr 和 Radarr 无法连接和“上传”种子到 Deluge。

  7. 我已经完全卸载了 Deluge 两次,但再次安装时,deluge-web 从我的自定义设置端口开始。这很奇怪,因为这意味着它没有完全卸载。

Deluge 是一款很棒的软件,但如果这样的事情继续发生,我已经完成了它。我想设置/修复它,这样我就再也不会有错误或问题了。因为我已经解决了它带来的所有问题。

server
  • 1 个回答
  • 607 Views
Martin Hope
Cas
Asked: 2021-03-12 13:22:35 +0800 CST

如何允许一个论点而不是论点并使用 getopts 对它们采取不同的行动

  • 1

我想为我的脚本设置 getopts,使其不接受参数 ( -p),但它也可以接受参数 ( -p library)。两者都需要被接受。它们(参数和无参数)都是允许的。应该允许参数是任何字符串。见下文:

while getopts "p:sdih" opt; do
                case ${opt} in
                        p )
                                #WHEN NO ARGUMENT IS GIVEN, DO THIS

                                selection="plex"

                                #WHEN AN ARGUMENT IS GIVEN, DO THIS

                                selection="plex"
                                argument=true
                                optarg="$OPTARG"
                                ;;

                        s )
                                selection="sonarr"
                                ;;

                        d )
                                selection="deluge"
                                ;;
                        i )
                                selection="info"
                                ;;

                        h )
                                usage | column -t -s "|"
                                exit
                                ;;
                        \? )
                                echo "Invalid option"
                                usage | column -t -s "|"
                                exit
                                ;;
                esac
        done 2>/dev/null
        shift $((OPTIND -1))

这就是它需要工作的方式。但我是 getopts 的新手,所以我还不知道该怎么做......

command-line
  • 1 个回答
  • 937 Views
Martin Hope
Cas
Asked: 2021-03-11 00:56:09 +0800 CST

如何“超时”一个函数,使其每 5 秒只运行一次,即使它每秒被调用多次

  • 0

见下文:

still_notify=false
has_been_notified=false
notify()
{
        $has_been_notified && return
        watching=$(if [[ $(GET http://$ipplexserver:32400/status/sessions?X-Plex-Token=$plexapitoken | grep -o "^</Video>$") ]]; then echo true; else echo false; fi)
        if [[ $watching = false ]]
        then
                clear
                echo "Updating notification"
                echo "--------------------------------"
                echo "Nobody is watching media on your plex server anymore"
                echo "You can now update plex"
                echo "-----"
                echo "You see this message because you chose to be notified when you were trying to update plex"
                echo "--------------------------------"
                sed -i "s|^still_notify=true$|still_notify=false|" $filelocation/advancedplexapi.sh
                read -rp "continue | update: " notifyoption
                if [[ ${notifyoption,,} = "continue" ]]
                then
                        echo "this is to exit out of the if statement" >> /dev/null

                elif [[ ${notifyoption,,} = update ]]
                then
                        option=update
                fi
                has_been_notified=true
        fi
}

if [[ $still_notify = true ]]
then
        trap notify DEBUG
fi

if [[ if-statement ]]
then
       sed -i "s|^still_notify=false$|still_notify=true|" $filelocation/advancedplexapi.sh
       trap notify DEBUG
fi

这是我脚本中的通知系统。当底部的 if 语句运行时,脚本继续,但在后台,它检查 plex api,如果 if 语句为真,它会显示一条消息。每次在脚本中执行命令时(由于在 trap 命令中使用了 DEBUG),它都会检查 api(请参阅监视变量)。我的脚本非常大(2800 行),它每秒运行多次通知函数(有时每秒 10 次)。这使得我的脚本非常慢(由于 api 请求的数量),有时甚至无法使用,而且该函数甚至不必运行那么多次。

我想要它,这样一旦函数运行,它就不能在接下来的 5 秒内运行,无论它被陷阱命令调用多少次。就像函数的睡眠/超时。我尝试了以下但没有奏效:

timeout=false
still_notify=false
has_been_notified=false
notify()
{
        if [[ $timeout = false ]]
        then
        sed -i "s|^timeout=false$|timeout=true|" $filelocation/advancedplexapi.sh
        $has_been_notified && return
        watching=$(if [[ $(GET http://$ipplexserver:32400/status/sessions?X-Plex-Token=$plexapitoken | grep -o "^</Video>$") ]]; then echo true; else echo false; fi)
        if [[ $watching = false ]]
        then
                clear
                echo "Updating notification"
                echo "--------------------------------"
                echo "Nobody is watching media on your plex server anymore"
                echo "You can now update plex"
                echo "-----"
                echo "You see this message because you chose to be notified when you were trying to update plex"
                echo "--------------------------------"
                sed -i "s|^still_notify=true$|still_notify=false|" $filelocation/advancedplexapi.sh
                read -rp "continue | update: " notifyoption
                if [[ ${notifyoption,,} = "continue" ]]
                then
                        echo "this is to exit out of the if statement" >> /dev/null

                elif [[ ${notifyoption,,} = update ]]
                then
                        option=update
                fi
                has_been_notified=true
        fi
}

while true
do
        sleep 5s
        sed -i "s|^timeout=true$|timeout=false|" $filelocation/advancedplexapi.sh
done &

if [[ $still_notify = true ]]
then
        trap notify DEBUG
fi

if [[ if-statement ]]
then
       sed -i "s|^still_notify=false$|still_notify=true|" $filelocation/advancedplexapi.sh
       trap notify DEBUG
fi
command-line
  • 1 个回答
  • 87 Views
Martin Hope
Cas
Asked: 2021-03-06 06:24:38 +0800 CST

如何在脚本中制作通知系统

  • 0

我有一个(至少对我来说)非常复杂的问题。

见下文:

#! /bin/bash

notify=false

a=0
while ((a <= 50))
do
    echo $a
    a=$(echo "$a+1" | bc)
    sleep 3s
done

当我运行脚本时,while 循环开始执行。完成后,脚本退出。

问题:

如果我将notify脚本中的变量设置为 true,则需要发生一些事情。那就是它notify_now在 $a 达到 25 时将变量(例如 )设置为 true。当notify_now设置为 true 时,它​​会回显一个不会中断 while 循环的通知。见下文:

...
24
25
The variable $a has reached 25
26
...

但是当我设置notify为 false 时,它​​不会发出任何通知。见下文:

...
24
25
26
...

在我的实际情况下,执行以下操作不是一种选择:

#! /bin/bash

notify=false

a=0
while ((a <= 50))
do
    echo $a
    if ((a = 25)) && [[ $notify = true ]]
    then
    echo "The variable \$a has reached 25"
    fi
    a=$(echo "$a+1" | bc)
    sleep 3s
done

总之:

当变量设置为 true 时,我需要一段能够在循环外运行的代码。代码需要在后台运行,这样while循环才能在前台运行。当后台的那段代码注意到前台的变量 $a 已经达到 25 时,它在终端中回显了一个句子。

我走了多远:

  • 这段代码可能是一个将被调用的函数
  • 该函数将在后台运行,但在前台回显(使用&,但我真的不擅长,所以这就是我问这个的原因)
  • 代码将处于一个循环中,该循环将一直运行到 $a 达到 25(因此它将检查 $a 的速度与 while 循环的速度一样快,直到它达到 25)

但我似乎无法让任何实际代码工作。

谢谢!

command-line
  • 1 个回答
  • 123 Views
Martin Hope
Cas
Asked: 2021-02-12 00:46:29 +0800 CST

grep json 输出中的字符串

  • 2

我有一个 api 请求,它以 json 形式提供输出(形式?布局?正文?你怎么说?)。看这里:

    {
        "title": "Another Life (2019)",
        "alternateTitles": [
            {
                "title": "Another Life",
                "seasonNumber": -1
            }
        ],
        "sortTitle": "another life 2019",
        "seasonCount": 2,
        "totalEpisodeCount": 20,
        "episodeCount": 10,
        "episodeFileCount": 10,
        "sizeOnDisk": 2979171318,
        "status": "continuing",
        "overview": "Astronaut Niko Breckenridge and her young crew face unimaginable danger as they go on a high-risk mission to explore the genesis of an alien artifact.",
        "previousAiring": "2019-07-25T07:00:00Z",
        "network": "Netflix",
        "airTime": "03:00",
        "seasons": [
            {
                "seasonNumber": 1,
                "monitored": true,
                "statistics": {
                    "previousAiring": "2019-07-25T07:00:00Z",
                    "episodeFileCount": 10,
                    "episodeCount": 10,
                    "totalEpisodeCount": 10,
                    "sizeOnDisk": 2979171318,
                    "percentOfEpisodes": 100.0
                }
            },
            {
                "seasonNumber": 2,
                "monitored": true,
                "statistics": {
                    "episodeFileCount": 0,
                    "episodeCount": 0,
                    "totalEpisodeCount": 10,
                    "sizeOnDisk": 0,
                    "percentOfEpisodes": 0.0
                }
            }
        ],
        "tags": [],
        "added": "2020-12-02T15:01:43.942456Z",
        "ratings": {
            "votes": 26,
            "value": 6.0
        },
        "qualityProfileId": 3,
        "id": 24
    }

我在一个长长的列表中有大约 20 个这样的输出。这是其中之一。

问题

在长长的列表中,我会选择 grep-ing "\"title\": \"Another Life (2019)\"",其中另一种生活 (2019) 可以是 20 个系列中的任何一个。需要获取 id(在输出的底部)。

但是这样做grep -Eo "\"id\": [0-9]{1,4}"是行不通的,因为我会得到 20 个 ID 作为输出。

做grep -Eo "\"title\": \"Another Life (2019)\".*\"id\": [0-9]{1,4}"也行不通。

做grep -A 100 "\"title\": \"Another Life (2019)\""然后 grep-ing id 也不起作用。

我似乎无法让它按我想要的方式工作。我在一般理解如何在 json 正文中抓取字符串时遇到问题。

如果我选择“Devs”,我想获取系列 Devs 的 id。如果我选择(无论是设置变量还是在命令中的某处插入名称)“越狱”,我想获得越狱系列的 id。

谢谢!

command-line
  • 1 个回答
  • 2967 Views
Martin Hope
Cas
Asked: 2021-01-29 07:23:38 +0800 CST

当变量与列表中的一个字符串匹配时使 if 语句为真

  • 1

我有一个命令将输出以下(curl -sSL $location | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]"):

Films
TV Series

我需要做一个 if 语句,其中一个变量需要匹配其中一个。例如

if [[ $option = Films ]] || [[ $option = "TV Series" ]]
then
    echo "True"
fi

但问题是,电影和电视剧可以改变。名称可以不同。并且有可能存在更多字符串,例如Films, TV Series, Music, Radio etc. etc.or movie, serie, radio, music。我需要得到它,以便变量 ( $option) 能够匹配来自命令的任何输出。它不必匹配它们中的每一个,只需一个就足够了,例如

Output command:
Films
TV Series
Radio

$option=TV Series -> True
$option=Radio -> True

Output command:
Films

$option=Films -> True
$option=radio -> False
command-line
  • 3 个回答
  • 67 Views
Martin Hope
Cas
Asked: 2021-01-22 05:44:31 +0800 CST

使用 xargs 和变量

  • 4

嘿,我有一个问题。

这是我正在使用的命令(在 的地方echo $file是一个不同的命令。我简化了它):

find /home/cas/plex-media/series/ -type f -name "*" ! -name "*.srt" -print0 | sort | xargs -0 -n1 -I{} file={} && echo $file

它说这file={}不是命令,这是真的,因为它是一个变量。我每次都需要将该变量设置为输出的一行,就像 xargs 对命令所做的那样。但是我需要它来填充变量,然后为排序输出的每一行使用该变量运行该命令。

例子:

作为输入(又名排序输出):

/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E01 - Pokémon - I Choose You!.mp4
/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E02 - Pokémon Emergency.mp4
/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E03 - Ash Catches a Pokémon.mp4 

我希望 xargs 每次都如何执行它:

file=/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E01 - Pokémon - I Choose You!.mp4 && echo /home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E01 - Pokémon - I Choose You!.mp4
file=/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E02 - Pokémon Emergency.mp4 && echo /home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E02 - Pokémon Emergency.mp4
file=/home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E03 - Ash Catches a Pokémon.mp4 && echo /home/cas/plex-media/series/Pokémon/Season 1/Pokémon - S01E03 - Ash Catches a Pokémon.mp4

我不能这样做echo {},因为我有多个地方是我{}需要填写的命令,而且我有很多command {} $(other command {}). 所以我用变量替换了所有需要排序输出的地方$file。因为那时 xargs 只需要更改一次变量并运行命令。然后更改变量并再次运行命令等。

我希望您了解我的问题以及我的目标是什么。你能帮助我吗?

谢谢!

command-line
  • 1 个回答
  • 4282 Views
Martin Hope
Cas
Asked: 2021-01-09 03:37:02 +0800 CST

如果它们是正确的,如何比较两个链接

  • 0

我有个问题。我将首先展示代码(用 bash 编写)。

#! /bin/bash

oldlink="https://downloads.plex.tv/plex-media-server-new/1.21.1.3876-3c3adfcb4/debian/plexmediaserver_1.21.1.3876-3c3adfcb4_amd64.deb"
newlink=$(curl -s -S https://plex.tv/pms/downloads/5.json | grep -o 'Ubuntu (16.04+) / Debian (8+) - Intel/AMD 64-bit","build":"linux-x86_64","distro":"debian","url":"https://downloads.plex.tv/plex-media-server-new/.*/debian/plexmediaserver_.*_amd64.deb","checksum":".*"},{"label":"Ubuntu (16.04+) / Debian (8+) - ARMv8' | grep -o https://.*.deb)
correctlink="https://downloads.plex.tv/plex-media-server-new/.*/debian/plexmediaserver_.*_amd64.deb"

if [[ $newlink = $correctlink ]]
then
        echo "new link is correct"
else
        echo "new link isn't correct"
fi

我有一个永远不会改变的链接(老实说它有时会改变,因为这段代码是更大脚本的一部分,但现在我们会说它是静态的)(oldlink)。每次运行脚本时都会更新新链接 (newlink)。newlink 之后的命令输出与 oldlink 中的链接完全相同。如果有新版本,除了版本号 (1.21.1.3876_3c3adfcb4)。

上面的代码运行时,表示newlink和oldlink不同(大部分时候都是新版本,因为链接中的版本号当然会改变,所以链接也会不同)。如果链接相同,它将永远不会运行。运行此代码时,它们总是不同的。

我想要做的是将 oldlink 和 newlink 相互比较。oldlink 和 newlink 彼此不同。我想检查差异是版本号还是链接的不同部分。

它应该如何工作

oldlink = "https://downloads.plex.tv/plex-media-server-new/1.21.1.3876-3c3adfcb4/debian/plexmediaserver_1.21.1.3876-3c3adfcb4_amd64.deb"

newlink = "https://downloads.plex.tv/plex-media-server-new/1.22.4.3876-3c3adfcb4/debian/plexmediaserver_1.22.4.3876-3c3adfcb4_amd64.deb"

[echo] new link is correct

==============================================

old link = "https://downloads.plex.tv/plex-media-server-new/1.21.1.3876-3c3adfcb4/debian/plexmediaserver_1.21.1.3876-3c3adfcb4_amd64.deb"

newlink = "https://this.is.something.else.hello/plex-media-server-new/1.21.1.3876-3c3adfcb4/blablabla/plexmediaserver_1.21.1.3876-3c3adfcb4_amd64.deb"

[echo] new link isn't correct

所以,当版本号改变时,没关系。当链接的其他内容发生变化时,就不行了。这就是它应该如何工作的方式。

我想如何检查,是将newlik与标准(正确链接)进行比较。如果它们匹配,则它是一个正确的链接。因为如果版本号不同,正确链接仅与新链接匹配。没有什么不同的。

它实际上是如何工作的

它提供随机输出。有时它给出正确的,有时是错误的。我一直无法找到一个结构,它什么时候做错了,什么时候做对了。我觉得它与正确链接中的 * 有关。我试过 .* 和 * 但这并没有改变结果。

我该如何解决这个问题,或者有更好的方法来做到这一点。与修复相比,我更喜欢更好/更短/更快/更简单的方法。谢谢!

command-line
  • 1 个回答
  • 56 Views
Martin Hope
Cas
Asked: 2020-12-24 07:04:28 +0800 CST

如何从路径列表中获取系列标题?

  • 2

我有以下命令:

find /home/cas/plex-media/series/ -type f -name '*.srt' | grep -v .en.srt

它将找到所有.srt不在.en.srt. 目录和子目录中的文件series。

这会给我一个看起来像这样的列表:

/home/cas/plex-media/series/Scorpion/Season 4/Scorpion - S04E06 - Queen Scary.srt
/home/cas/plex-media/series/Scorpion/Season 4/Scorpion - S04E03 - Grow a Deer, A Female Deer.srt
/home/cas/plex-media/series/Devs/Season 1/Devs - S01E03 - Episode 3.srt
/home/cas/plex-media/series/Modern Family/Season 8/Modern Family - S08E21 - Alone Time.srt

这是一个简化版本。例如,可能有 5 或 300 个输出,其中可能有 8 或 50 倍 Scorpion。输出变化很大。

我试图找到一个命令(我可以在原始命令后面使用管道),这将给我结果:

Scorpion, Devs, Modern Family

并不是:

Scorpion, Scorpion, Scorpion, Scorpion, Devs, Devs, Modern Family, Modern Family, Modern Family, 
Modern Family, Modern Family, Modern Family, etc.. 

你明白了。每场演出,一个输出。不是每个文件。

它可以在另一个布局中。这并不重要(尽管我更喜欢上面的布局)。

我一直在尝试使用 grep,但我就是做不到。所以我基本上是在问:你知道我怎样才能得到上面的输出吗?

谢谢。

command-line
  • 1 个回答
  • 93 Views
Martin Hope
Cas
Asked: 2020-12-22 07:39:24 +0800 CST

如何识别是否有人正在为我的 bash 脚本观看 plex 媒体

  • 2

嘿,我有一个(至少对我来说)相当困难的问题。

我的 Ubuntu 服务器上安装了 plex 媒体服务器。我正在编写一个脚本,它将每 12 小时自动检查 plex 服务器是否有更新,如果有,它将自动下载。它是用 bash 编写的,因为这是我知道的唯一语言。

#! /bin/bash

ogpath=$(pwd)
path=$(locate -br '^12hpmscheck.sh$' | xargs dirname)

cd "$path"
#step 1
oldlink="https://downloads.plex.tv/plex-media-server-new/1.21.1.3830-6c22540d5/debian/plexmediaserver_1.21.1.3830-6c22540d5_amd64.deb"
newlink=$(sudo wget https://plex.tv/pms/downloads/5.json && sudo chmod 777 "$path/5.json" && sudo chmod a+rwx "$path/5.json" && grep -o 'Ubuntu (16.04+) / Debian (8+) - Intel/AMD 64-bit","build":"linux-x86_64","distro":"debian","url":"https://downloads.plex.tv/plex-media-server-new/.*/debian/plexmediaserver_.*_amd64.deb","checksum":".*"},{"label":"Ubuntu (16.04+) / Debian (8+) - ARMv8' "$path/5.json" | grep -o 'https://.*.deb')

if [[ "$oldlink" == "$newlink" ]]
then
        echo "no new version"
        rm "$path/5.json"
        cd "$ogpath"
        sleep 12h
        $path/12hpmscheck.sh
else
        echo "new version"

        #step 3
        wget "$newlink"
        echo "downloaded new version"
        sed -i "s|$oldlink|$newlink|" "$path/12hpmscheck.sh"
        echo "updated old link"

        #step 4
        sudo systemctl stop plexmediaserver.service
        echo "stopped plexmediaserver.service"

        #step 5
        sudo dpkg -i plexmediaserver*.deb
        echo  "installed new version"

        #step 6
        sudo systemctl start plexmediaserver.service
        echo "started plexmediaserver.service"

        #step 7
        rm 5.json
        rm plexmediaserver*.deb
        cd "$ogpath"
        sleep 12h
        $path/12hpmscheck.sh
fi

说明:它首先检查脚本的路径以及运行它的路径(vars ogpath 和路径)。某些命令需要这些变量。

然后我们有 var oldlink。除非找到新链接,否则该链接是最新链接。除非有新版本,否则这个不会改变。

然后我们有 var newlink。此变量将每 12 小时更新一次。长话短说,它下载了用于下载服务器的 plex 网站,并找到了 Ubuntu 64 位的链接。如果有更新,除了版本号之外,结果看起来与 oldlink 相同。

if-then-else 部分:如果 oldlink 和 newlink 相同(也就是没有新版本),它会休眠 12 小时,然后再次运行。如果它们不匹配(也就是有新版本),它会下载新链接,停止 pms,更新 pms,启动 pms,更新 oldlink 以成为新版本,然后再次休眠 12 小时。

现在您可能已经注意到#step 1,3,4,5,6,7。那些是因为我在制作剧本之前为自己做了一个笔记。我制定了步骤以及在这些步骤中需要发生什么。这让我很清楚我需要做什么。但是没有第 2 步。那是因为第 2 步如下:如果有人现在正在观看 plex(另外两个人可以访问服务器并可以观看内容),请等待 20 分钟并再次运行脚本。如果没有人在看,请继续。

我曾计划通过 wget 连接到 plex-dashboard 的链接(您可以在其中查看是否有人在观看)并 grep 一个仅在有人观看时才存在的字符串来检查这一点。在该页面的代码中,有人观看时可以找到以下字符串(没有人观看时找不到):NowPlaying-nowPlayingList。我会 grep 该字符串,当输出匹配“NowPlaying-nowPlayingList”时,有人正在观看,它会等待 20 分钟。当输出为空时,它会继续。

问题是我无法获取该仪表板页面,因为它有 # 并且人们告诉我这意味着它是一个“动态 Java”页面。我不明白。所以我搜索了其他方法来检查并想出了我可以从本地代码中 grep 那个字符串的想法。Pms 安装在我的服务器上,因此机器上必须有它的代码。如果我找到与该仪表板有关的代码,我可以在那里搜索一个字符串。

问题是:我一般找不到任何与 pms 的纯功能相关的代码,更不用说仪表板的代码了。我在哪里可以找到代码,或者是否有其他我没有想到的检查方法。我更喜欢使用 bash,但如果必须,我可以改用另一种语言。虽然我必须重写完整的脚本。

如果有办法更好/更快地编写代码的其他部分,也欢迎这些建议!

希望您能提供帮助。谢谢!

scripts command-line bash plex
  • 1 个回答
  • 928 Views
Martin Hope
Cas
Asked: 2020-12-17 11:46:15 +0800 CST

使用定位管道时,Grep -v 不起作用

  • 0

我有以下命令:

locate -br '^test.sh$'

输出是:

/home/cas/scripts/test.sh

我想要没有文件名的路径。所以我做了以下从输出中删除 test.sh :

locate -br '^test.sh$' | grep -v test.sh

我预计输出是:

/home/cas/scripts/

但相反,我只是没有得到输出。当我按下回车键时,我没有得到任何输出,它只是等待下一个命令。见下图

在此处输入图像描述

没有任何输出。我什至试图反转-grep 一些不同的东西,'cas',但它不会给出任何输出。看起来grep -v只是行不通。但是正常的 grep(所以不倒置)确实有效。为什么它不起作用?或者有没有更好的方法可以从任何地方找到文件的路径,但输出中没有文件名(目标是 get /home/cas/scripts/)?

command-line bash grep text-processing
  • 1 个回答
  • 332 Views

Sidebar

Stats

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

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve