为什么我的 strace 命令对鱼不起作用?

问题描述

我正在尝试启动一个可以用 Bash 启动但不能用 Fish 启动的命令:

  • Bash 上运行良好:
$ sudo strace -f -s3000 -p $(pgrep -f teams -d " -p ") -o /tmp/debug.log
strace: Process 49774 attached with 32 threads
strace: Process 49778 attached
strace: Process 49780 attached
strace: Process 49817 attached with 10 threads
strace: Process 49824 attached with 6 threads
strace: Process 49848 attached with 13 threads
strace: Process 55055 attached with 6 threads
strace: Process 56914 attached with 17 threads
strace: Process 56965 attached with 44 threads
strace: Process 57041 attached with 10 threads
  • Fish 上,我正在尝试相同的方法但没有“$”,但出现错误
$ sudo strace -f -s3000 -p (pgrep -f teams -d " -p ") -o /tmp/debug.log
strace: Invalid process id: '-p'

这个 strace 是跟踪 Teams 的所有进程,这里只是 pgrep 命令(仅供参考):

$ pgrep -f teams -d " -p "
49774 -p 49778 -p 49780 -p 49817 -p 49824 -p 49848 -p 55055 -p 56914 -p 56965 -p 57041

有什么想法吗?

解决方法

与 bash 不同,fish 仅在换行符上拆分命令替换,而不是空格或制表符或其他任何东西。

这意味着当您的 9774 -p 49778 -p 49780 作为一个参数传递给 strace 时,您希望它是 5 - 9774,-p49778-p49780

解决方案是使用 string split 显式拆分它:

sudo strace -f -s3000 -p (pgrep -f teams -d " -p " | string split " ") -o /tmp/debug.log
,

您可以分段构建命令选项:

set opts -f -s3000 -o /tmp/file
for pid in (pgrep -f team); set opts $opts -p $pid; end

sudo strace $opts

这利用了鱼变量的列表性质。

,

首先,在变量中设置 pgrep 并用空格分割字符串

services:
  zeebe:
#    restart: always
    container_name: chai_maker
    image: registry.uzbekistan.uz/cicd/chai_s_molokom:0.26.0
    ports:
      - 26500:26500
      - 26501:26501
      - 26502:26502
      - 9600:9600 # monitoring
#    networks:
#      - zibi
    environment:
      TIME_ZONE: 'Asia/Khudzhand'
      ZEEBE_BROKER_GATEWAY_ENABLE: 'true'
      ZEEBE_BROKER_NETWORK_HOST: '0.0.0.0' # this broker's host (advertized host)
      ZEEBE_BROKER_NETWORK_ADVERTISEDHOST: '{{ ansible_default_ipv4.address }}'
      ZEEBE_HOST: '0.0.0.0'
      ZEEBE_BROKER_NETWORK_MAXMESSAGESIZE: '512KB'
      ZEEBE_BROKER_NETWORK_COMMANDAPI_PORT: '26501'
      ZEEBE_BROKER_NETWORK_INTERNALAPI_PORT: '26502'
      ZEEBE_BROKER_NETWORK_MONITORINGAPI_PORT: '9600'
      ZEEBE_BROKER_CLUSTER_NODEID: '{{ '
      ZEEBE_BROKER_CLUSTER_PARTITIONSCOUNT: '1'
      ZEEBE_BROKER_CLUSTER_REPLICATIONFACTOR: '6' # set to 6
      ZEEBE_BROKER_CLUSTER_CLUSTERSIZE: '6' # set to 6
      ZEEBE_BROKER_CLUSTER_CLUSTERNAME: 'pidoras'
      ZEEBE_BROKER_THREADS_CPUTHREADCOUNT: '2'
      ZEEBE_BROKER_THREADS_IOTHREADCOUNT: '2'
      ZEEBE_BROKER_EXPORTERS_ELASTICSEARCH_ARGS_URLS: 'http://192.168.2.13:9200'
      ZEEBE_DEBUG: 'false'
      # JAVA_TOOL_OPTIONS: '-XX:MaxRAMPercentage=25.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/zeebe/data -XX:ErrorFile=/usr/local/zeebe/data/zeebe_error%p.logo -XX:+ExitOnOutOfMemoryError'
      ZEEBE_BROKER_CLUSTER_INITIALCONTACTPOINTS: '10.0.88.80:26502,10.0.88.81:26502,10.0.88.82:26502,10.0.88.83:26502,10.0.88.84:26502,10.0.88.85:26502,10.0.88.86:26502' # comma separated host list
    volumes:
      - ${PWD}/data:/usr/local/zeebe/data
      - ${PWD}/exporters:/usr/local/zeebe/exporters
      - ${PWD}/application.yaml:/usr/local/zeebe/config/application.yaml
      - ${PWD}/log4j2.xml:/usr/local/zeebe/config/log4j2.xml
networks:
  zibi:
    driver: host

然后调用它:

$ set PROCS (string split ' ' (pgrep -f teams -d " -p"))