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

NarūnasK's questions

Martin Hope
NarūnasK
Asked: 2020-01-13 14:25:45 +0800 CST

bash -c 完成后如何保留交互式shell?

  • 1

我有一个玩具脚本,它打印出$SHLVL和 shell 调用设置:

$ cat tst.sh 
echo "Level: $SHLVL"
echo "Options: $-"

如果我source在当前的 shell 中它可以按预期工作:

$ source tst.sh 
Level: 1
Options: himBHs

如果它sourced在子外壳中,那么再没有什么太令人兴奋的了:

$ /bin/bash
$ source tst.sh 
Level: 2
Options: himBHs

使用设置运行它-c给了我稍微不同的输出:

$ /bin/bash -c 'source tst.sh'
Level: 2
Options: hBc

因此,我提供了缺少的选项:

$ /bin/bash -sic 'source tst.sh'
Level: 2
Options: himBHcs

请注意,每次sourced我使用该-c设置的脚本时,在脚本中的最后一个命令完成后,子外壳程序就会退出。这是我想阻止的事情,因此在脚本中的最后一个命令之后,我应该保留在interactive子 shell 中。

基本上我想复制以下步骤序列,但使用-c:

$ /bin/bash
$ source tst.sh
bash shell
  • 1 个回答
  • 153 Views
Martin Hope
NarūnasK
Asked: 2019-12-19 07:57:02 +0800 CST

SSH ProxyJump 应用错误的用户名

  • 2

鉴于以下情况ssh.cfg:

Host bastion
  Hostname xx.yyy.169.100
  User ubuntu
  IdentityFile ./the-key.pem

Host 10.250.*.*
  ProxyJump %r@bastion
  User core
  IdentityFile ./the-key.pem

尝试通过 连接到服务器bastion失败,因为 ssh 应用了错误的用户名:

$ ssh -vvF ssh.cfg 10.250.198.76
...
debug1: Reading configuration data ssh.cfg
debug1: ssh.cfg line 1: Applying options for bastion
debug2: resolve_canonicalize: hostname xx.yyy.169.100 is address
debug2: ssh_connect_direct
debug1: Connecting to xx.yyy.169.100 [xx.yyy.169.100] port 22.
debug1: Connection established.
debug1: identity file ./the-key.pem type -1
debug1: identity file ./the-key.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to xx.yyy.169.100:22 as 'core'
...

我希望 sshubuntu在连接到堡垒时应用core用户,并且仅在连接到目标服务器时应用用户。

有没有办法按照我想要的方式配置它?

ssh openssh
  • 1 个回答
  • 2537 Views
Martin Hope
NarūnasK
Asked: 2019-05-15 11:56:10 +0800 CST

如何将 TOKENS 与 ssh LocalForward 指令一起使用?

  • 1

具有以下内容ssh_config:

Match all
  IdentityFile /opt/ssh/id_rsa
  StrictHostKeyChecking no
  ServerAliveInterval 30
  ServerAliveCountMax 3
  ControlMaster auto
  ControlPersist 300
  StreamLocalBindMask 0111
  StreamLocalBindUnlink yes
  ExitOnForwardFailure yes
  Compression yes
  BatchMode yes

Host example
  LocalForward /opt/ssh/soc/%n_mysql.socket 127.0.0.1:3306
  ControlPath /opt/ssh/soc/%n.socket
  HostName example.com
  User user
  Port 22

创建了两个unix-socket文件:

# ls -1 /opt/ssh/soc
example.socket
%n_mysql.socket

显然LocalForward指令不喜欢令牌......

我想知道为什么以及是否有其他方法可以实现这一目标?

我看到它LocalCommand接受以下标记:%%, %C, %d, %h, %i, %l, %n, %p, %r, %T, 和%u. 它可以以某种方式用于实现我想要的吗?

我尝试了以下配置,但它只创建ctrl套接字,而不是那个mysql。

Host example
  PermitLocalCommand yes
  LocalCommand ssh -F /opt/ssh/config -S /opt/ssh/sockets/%n.socket -TNL /opt/ssh/sockets/%n_mysql.socket:127.0.0.1:3306 -p %p -l %u %h
  ControlPath /opt/ssh/soc/%n.socket
  HostName example.com
  User user
  Port 22
ssh ssh-tunneling
  • 1 个回答
  • 475 Views
Martin Hope
NarūnasK
Asked: 2019-04-25 13:39:14 +0800 CST

将 bash 脚本中的 args 传递给脚本中的函数

  • 4

我的脚本:

#! /bin/bash --

set -x

## docker-compose wrapper
compose_fn() {
  local ENV="${1}"
  local VERB="${2}"
  local SERVICE="${3}"
  local CMD="docker-compose -f ${ENV}.yml"
  case "${VERB}" in
    (exec)
      shift "$#" # remove args passed to this fn
      # Execute a command in a running container.
      if [ -n "${SERVICE}" ]; then
        ${CMD} "${VERB}" "${SERVICE}" "$@"
      else
        echo "## Err: You must specify service name..."
        exit 1
      fi
    ;;
  esac
}

compose_fn "${1}" "${2}" "${3}"

以下错误让我很难受:

$ ./tst.sh dev exec django sh
+ compose_fn dev exec django
+ local ENV=dev
+ local VERB=exec
+ local SERVICE=django
+ local 'CMD=docker-compose -f dev.yml'
+ case "${VERB}" in
+ shift 3
+ '[' -n django ']'
+ docker-compose -f dev.yml exec django
Execute a command in a running container

Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]

Options:
....

我的错误在哪里?怎样才能做得更好?

据我所知,我已经将 4 个 args 传递[dev, exec, django, sh]给脚本,然后在脚本中删除了 3 ( shift 3),因此sh应该留在$@var 中。

bash shell-script
  • 1 个回答
  • 1600 Views
Martin Hope
NarūnasK
Asked: 2018-09-05 12:03:26 +0800 CST

使用 bash 变量间接访问时如何访问数组的更多成员?

  • 2

考虑以下示例,它似乎与 index 一起工作正常0:

$ a1=(1 2 3)
$ a2=(a b c)
$ for x in a1 a2; do echo "${!x}"; done
1
a
$ for x in a1 a2; do echo "${!x[0]}"; done
1
a

但是对于索引1,它什么也不打印:

$ for x in a1 a2; do echo "${!x[1]}"; done    

数组本身就很好:

$ echo "${a1[1]} ${a2[1]}"
2 b

编辑 - 基于ilkkachu答案的现实生活用例

SHIBB=(https://shibboleth.net/downloads/service-provider/3.0.2/ shibboleth-sp-3.0.2 .tar.gz)
XERCES=(http://apache.mirrors.nublue.co.uk//xerces/c/3/sources/ xerces-c-3.2.1 .tar.gz)
XMLSEC=(http://apache.mirror.anlx.net/santuario/c-library/ xml-security-c-2.0.1 .tar.gz)
XMLTOOL=(http://shibboleth.net/downloads/c++-opensaml/latest/ xmltooling-3.0.2 .tar.gz)
OPENSAML=(http://shibboleth.net/downloads/c++-opensaml/latest/ opensaml-3.0.0 .tar.gz)

typeset -n x
for x in XERCES XMLSEC XMLTOOL OPENSAML SHIBB; do
  url="${x[0]}" app="${x[1]}" ext="${x[2]}"
  [ -f "./${app}${ext}" ] || wget "${url}${app}${ext}"
  tar -xf "./${app}${ext}"
  cd "./${app}" && ./configure && make -j2 && make install && ldconfig
  cd ..
done
bash bash-expansion
  • 1 个回答
  • 88 Views
Martin Hope
NarūnasK
Asked: 2017-12-31 13:36:30 +0800 CST

我应该使用哪种 ssh “跳转主机”变体?

  • 3

我知道至少有 3 种ssh配置变体jump_host可以连接到target_host:

Host jump_host
  HostName 1.2.3.4

# Variant - 1
Host target_host
  HostName 172.16.0.1
  ProxyCommand ssh -q -x jump_host 'netcat %h 22'

# Variant - 2
Host target_host
  HostName 172.16.0.1
  ProxyCommand ssh -q -x jump_host -W '%h:22'

# Variant - 3
Host target_host
  HostName 172.16.0.1
  ProxyJump jump_host

这些方法中的任何一种是否比其他方法更好?配置 2 和 3 之间有什么区别(如果有的话)?显然配置 1 需要netcat手头,所以它最不吸引人。

ssh
  • 1 个回答
  • 2197 Views
Martin Hope
NarūnasK
Asked: 2017-12-07 05:24:42 +0800 CST

Preseed 指令跳过另一个 CD/DVD 扫描

  • 6

请看下图,是否有preseed跳过此Debian9安装步骤的指令?

目前我使用以下与包管理器相关的配置:

### Apt setup
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/local0/source boolean true

### Package selection
tasksel tasksel/first multiselect standard

### Mirror settings
d-i mirror/country string manual
d-i mirror/http/hostname string httpredir.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

Debian9 安装程序

debian debian-installer
  • 1 个回答
  • 4064 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