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

s.k's questions

Martin Hope
s.k
Asked: 2024-03-10 03:10:38 +0800 CST

换行符相当于 bash 脚本中的 && 吗?

  • 5

我只是想知道,在 bash 脚本中,新行在功能上是否 100% 等同于&&?

例如:

#!/bin/bash

7z x "${file}"

mv "${file}" "${new_file}"

与

#!/bin/bash

7z x "${file}" && mv "${file}" "${new_file}"

GNU bash,版本 5.1.16(1)-release (x86_64-pc-linux-gnu)

bash
  • 1 个回答
  • 58 Views
Martin Hope
s.k
Asked: 2024-02-28 18:03:33 +0800 CST

使用 sed 将字符串 ${FOO} 替换为 ${'$'}{BAR}

  • 5

我的这个字符串在一个文件中出现了 N 次:${FOO} 我必须用这个字符串替换它:${'$'}{BAR}

这是我目前的状态:

sed "s/\\${FOO}/\\${'\\$'}{BAR}/" file.txt但这引发了“不良替代”。

我怎样才能用sed(版本4.8)正确实现这一目标?

sed
  • 1 个回答
  • 27 Views
Martin Hope
s.k
Asked: 2023-03-30 20:27:22 +0800 CST

如何获取当前终端ID

  • 14

相关:如何获取当前终端名称?

但我只想要当前终端的 ID,例如tty返回时/dev/pts/11我只想打印11。

我的想法是在我的文件中变量\u中的用户名之后的 shell 提示符中添加此信息:PS1.bashrc

想要的结果:username11@localhost:~$

目前我有:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u$(tty)@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

这使:username/dev/pts/11@localhost:~$

bash
  • 1 个回答
  • 515 Views
Martin Hope
s.k
Asked: 2023-03-11 01:43:20 +0800 CST

视觉对齐 CSV 文件的列

  • 8

使用sedor awk,是否可以在视觉上对齐 CSV 文件中的列?

例如:

例如来自:

a,b,c,some stuff,"some, other, stuff",d,2023-03-10 18:37:00
y,x,z,t,cool,thing,2022-04-12 21:44:00

到:

a, b, c, some stuff,"some, other, stuff",     d, 2023-03-10 18:37:00<EOL>
x, y, z,          t,                cool, thing, 2022-04-12 21:44:00<EOL>

有一些双引号字段包含文本和逗号。

我尝试column了bsdmainutils一下,但显然无法处理此类数据。

csv
  • 3 个回答
  • 285 Views
Martin Hope
s.k
Asked: 2022-10-31 07:12:50 +0800 CST

查找两者的路径:C++ 编译所需的 wxWidgets_LIBRARIES 和 wxWidgets_INCLUDE_DIRS 变量

  • 5

在基于 Debian 的操作系统上,我如何找出 wxWidgets_LIBRARIES 和 wxWidgets_INCLUDE_DIRS 路径?

实际上,在尝试编译软件时,我实际上遇到了 cmake 的此类错误:

CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
  wxWidgets_INCLUDE_DIRS)
Call Stack (most recent call first):
  /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.18/Modules/FindwxWidgets.cmake:1008 (find_package_handle_standard_args)
  src/pacakge_core/CMakeLists.txt:16 (find_package)

因此,我正在寻找传递给我的 cmake 命令的正确路径。

debian
  • 1 个回答
  • 15 Views
Martin Hope
s.k
Asked: 2022-10-31 05:32:56 +0800 CST

在 Ubuntu 上使用 checkinstall 将 deb 文件构建安装到基于 Debian 的 docker 容器中

  • 5

我在我的 Ubuntu 22.04 笔记本电脑上编译了一个 C++ 软件,并用来checkinstall安装它。这构建了相应的.deb文件,这很好。

但现在我想将该.deb文件安装到基于“Debian GNU/Linux 11 (bullseye)”的 docker 容器中并dpkg显示此错误:

# dpkg --install mypackage-8.0.0_20221030-1_amd64.deb 
dpkg-deb: error: archive 'mypackage-8.0.0_20221030-1_amd64.deb' uses unknown compression for member 'control.tar.zst', giving up
dpkg: error processing archive mypackage-8.0.0_20221030-1_amd64.deb (--install):
 dpkg-deb --control subprocess returned error exit status 2
Errors were encountered while processing:
 mypackage-8.0.0_20221030-1_amd64.deb

我怎样才能将这个.deb文件安装到我的容器中而无需再次编译软件(这意味着将所有 C++ 构建工具安装到我的容器中,我想避免这种情况......)?

debian
  • 1 个回答
  • 26 Views
Martin Hope
s.k
Asked: 2022-02-17 05:34:13 +0800 CST

在没有明确指定的情况下打开 SSH 隧道时使用的默认绑定地址是什么

  • 0

打开 SSH 隧道时,例如在 Ubuntu 21.10 上如下所示:

$ ssh -f -N -L 1234:127.0.0.1:5678 user@server

引擎盖下使用的默认绑定地址是什么(如果有)?

这是否等同于:

$ ssh -f -N -L 127.0.0.1:1234:127.0.0.1:5678 user@server

或者

$ ssh -f -N -L 0.0.0.0:1234:127.0.0.1:5678 user@server

或类似的东西

$ ssh -f -N -L *:1234:127.0.0.1:5678 user@server

?

sshd ssh
  • 1 个回答
  • 243 Views
Martin Hope
s.k
Asked: 2022-02-06 09:15:44 +0800 CST

Autossh 在本地的工作方式与在远程服务器上的工作方式不同

  • 0

如果我autossh在本地机器上启动如下:

autossh -M 20000 -f - nNT -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server-B

它会在后台自动启动以下ssh命令,这是我所期望的:

ps aux | grep -i ssh
/usr/lib/autossh/autossh -M 20000 -f - nNT -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server
/usr/bin/ssh -L 20000:127.0.0.1:20000 -R 20000:127.0.0.1:20001 -N -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server-B

但在远程服务器 A 上启动的相同命令仅显示ps:

/usr/lib/autossh/autossh -M 20000 -f - nNT -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server-B

似乎它没有启动底层ssh命令。

(请注意,如果我ssh在远程服务器 A 上手动启动命令,那么我可以正确连接到远程服务器 B。)

我无法弄清楚为什么该命令在远程计算机上的行为与在本地计算机上的行为不同......

这两个autossh版本都1.4g在我的本地计算机和远程服务器 A 上。

两台机器都在 Ubuntu 20.04 上。

编辑:

Per Stéphane Chazelas 的评论:在两台不同的远程机器上尝试命令时,我实际上注意到两种略有不同的行为:

1.

$ strace -fe execve autossh -M 20000  -f  -nNT -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server-B
execve("/usr/bin/autossh", ["autossh", "-M", "20000", "-f", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x7fff532c2f68 /* 40 vars */) = 0
strace: Process 23539 attached
[pid 23539] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=23539, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 23540 attached
[pid 23540] execve("/bin/egrep", ["egrep", "-q", "--", "-f?M ?[0-9]+"], 0x55b83714eae8 /* 38 vars */) = 0
[pid 23540] execve("/home/username/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/home/username/.local/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/home/username/anaconda3/condabin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/opt/blenderc/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/usr/local/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/usr/local/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/usr/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/usr/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = -1 ENOENT (No such file or directory)
[pid 23540] execve("/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x55b692ae0a28 /* 38 vars */) = 0
[pid 23540] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=23540, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
execve("/usr/lib/autossh/autossh", ["/usr/lib/autossh/autossh", "-M", "20000", "-f", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x55b83714f470 /* 38 vars */) = 0
strace: Process 23541 attached
[pid 23538] +++ exited with 0 +++
strace: Process 23542 attached
[pid 23542] execve("/usr/bin/ssh", ["/usr/bin/ssh", "-L", "20000:127.0.0.1:20000", "-R", "20000:127.0.0.1:20001", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x7ffce7ca53e0 /* 38 vars */) = 0
[pid 23542] +++ exited with 255 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=23542, si_uid=1000, si_status=255, si_utime=2, si_stime=0} ---
strace: Process 23543 attached
[pid 23543] execve("/usr/bin/ssh", ["/usr/bin/ssh", "-L", "20000:127.0.0.1:20000", "-R", "20000:127.0.0.1:20001", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x7ffce7ca53e0 /* 38 vars */) = 0

(最后 3 行以固定间隔无限重复,每次使用不同的进程 ID)

2.

$ strace -fe execve autossh -M 20000  -f  -nNT -L 192.168.144.1:5433:127.0.0.1:5432 remote-user@remote-server-B
execve("/usr/bin/autossh", ["autossh", "-M", "20000", "-f", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x7fff7be64dc8 /* 34 vars */) = 0
strace: Process 3850 attached
[pid  3850] +++ exited with 0 +++
strace: Process 3851 attached
[pid  3849] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3850, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
[pid  3851] execve("/bin/egrep", ["egrep", "-q", "--", "-f?M ?[0-9]+"], 0x55690bd42a08 /* 32 vars */) = 0
[pid  3851] execve("/usr/local/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = -1 ENOENT (No such file or directory)
[pid  3851] execve("/usr/local/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = -1 ENOENT (No such file or directory)
[pid  3851] execve("/usr/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = -1 ENOENT (No such file or directory)
[pid  3851] execve("/usr/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = -1 ENOENT (No such file or directory)
[pid  3851] execve("/sbin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = -1 ENOENT (No such file or directory)
[pid  3851] execve("/bin/grep", ["grep", "-E", "-q", "--", "-f?M ?[0-9]+"], 0x5637ad7d9958 /* 32 vars */) = 0
[pid  3851] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3851, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
execve("/usr/lib/autossh/autossh", ["/usr/lib/autossh/autossh", "-M", "20000", "-f", "-nNT", "-L", "192.168.144.1:5433:127.0.0.1:5432", "remote-user@remote-server-B"], 0x55690bd433a0 /* 32 vars */) = 0
strace: Process 3852 attached
[pid  3849] +++ exited with 0 +++
+++ exited with 1 +++

(然后它立即将控制台返回给用户)

ubuntu ssh
  • 1 个回答
  • 100 Views
Martin Hope
s.k
Asked: 2022-01-30 10:50:16 +0800 CST

Autossh 选项与其手册页中的内容不一致?

  • 0

我有一个幼稚的问题,但是通过阅读这个线程,例如:https ://superuser.com/questions/37738/how-to-reliably-keep-an-ssh-tunnel-open

可以在接受的答案中看到如何使用autossh,例如:

autossh -M 20000 -f -N your_public_server -R 1234:localhost:22 -C

但是从autossh https://manpages.ubuntu.com/manpages/focal/man1/autossh.1.html的手册页我只能看到 3 个可用选项-M:-f和-V.

在我的系统上同样的事情:

$ autossh --help
/usr/lib/autossh/autossh: invalid option -- '-'
usage: autossh [-V] [-M monitor_port[:echo_port]] [-f] [SSH_OPTIONS]

    -M specifies monitor port. Overrides the environment
       variable AUTOSSH_PORT. 0 turns monitoring loop off.
       Alternatively, a port for an echo service on the remote
       machine may be specified. (Normally port 7.)
    -f run in background (autossh handles this, and does not
       pass it to ssh.)
    -V print autossh version and exit.

Environment variables are:
    AUTOSSH_GATETIME    - how long must an ssh session be established
                          before we decide it really was established
                          (in seconds). Default is 30 seconds; use of -f
                          flag sets this to 0.
    AUTOSSH_LOGFILE     - file to log to (default is to use the syslog
                          facility)
    AUTOSSH_LOGLEVEL    - level of log verbosity
    AUTOSSH_MAXLIFETIME - set the maximum time to live (seconds)
    AUTOSSH_MAXSTART    - max times to restart (default is no limit)
    AUTOSSH_MESSAGE     - message to append to echo string (max 64 bytes)
    AUTOSSH_PATH        - path to ssh if not default
    AUTOSSH_PIDFILE     - write pid to this file
    AUTOSSH_POLL        - how often to check the connection (seconds)
    AUTOSSH_FIRST_POLL  - time before first connection check (seconds)
    AUTOSSH_PORT        - port to use for monitor connection
    AUTOSSH_DEBUG       - turn logging to maximum verbosity and log to
                          stderr

和选项从何而来-N?我没有找对地方吗?-R-C

ubuntu autossh
  • 1 个回答
  • 198 Views
Martin Hope
s.k
Asked: 2021-09-24 05:18:11 +0800 CST

在单引号子命令中转义单引号,本身在双引号命令中

  • 1

问题很简单如下:

watch "psql -d postgresql://user:pass@host:5432/dbname -c 'select id,name from table where name <> 'not available' order by id;'"

这个'not available'比较必须像Postgres 一样单引号。但是我无法找到正确转义这些单引号的方法,因为 psql 命令(我的意思是select...)本身已经是单引号,并且也在psqlfor watch 调用所需的双引号内。

如何解决这个问题?通过使用或使用多个双/单引号来转义这些单引号,
我几乎看到了所有可能的语法错误。\

bash ubuntu
  • 2 个回答
  • 625 Views
Martin Hope
s.k
Asked: 2021-09-23 03:43:33 +0800 CST

`watch` 一个不显示完整连接字符串的 PostgreSQL 查询

  • 0

我想与团队成员在线分享PostgreSQL数据库(托管在 dockerized Debian Bullseye 上)的一些实时修改watch(如果您知道任何其他工具,最好是pgAdmin4 ,但我无法找到一种方法观看现场修改,请告诉我)。

目前我正在这样做:

$  PGPASSWORD=***************
$ reset
$ watch -n 1.0 "psql \
-d postgresql://postgres:${PGPASSWORD}@localhost:5432/dbname \
  -c 'select id,name,customer,order,product from public.table where id in (1,2,3,4) order by (id)';"

这样密码就不会存储在 bash 历史记录中(请注意第一行前面的空格),并且在调用后它在屏幕上不再可见reset(主机在 Ubuntu 18.04 上)。

但是当watch命令启动时,它实际上在屏幕顶部显示了完整连接查询字符串到纯文本的“翻译”,因此显示了数据库密码(或任何其他变量):

Every 1.0s: psql -d postgresql://postgres:mysecretpassword@localhost:5439/dbname -c (...)
...

有隐藏的可能吗?

debian ubuntu
  • 2 个回答
  • 22 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve