linux shell有问

@Ta 2024-06-30发布,2024-06-30修改 155点击

shell脚本如下,为什么
①会再起一个同名子进程
②只能单例运行

# 在 shell 脚本中将输出复制一份到文件
# 输出重定到tee,错误重定向到输出
exec > >(tee -a output.log) 2>&1
# 原理是进程替换,缺点是会再起一个同名子进程,见如下
 \_ /bin/bash ./main.sh
 	\_ /bin/bash ./main.sh
 		\_ tee -a output.log.log
# 且此时脚本只能单例运行,若尝试多例运行报错如下
-bash: ./test.sh: /bin/bash: bad interpreter: Input/output error

小米MIX2s(白)

回复列表(4|隐藏机器人聊天)
  • @Ta / 2024-06-30 / /

    对了 我是./test.sh这样 运行会报错,如果是 bash test.sh 则是正常的
    小米MIX2s(白)

  • @Ta / 2024-06-30 / /

    问题已解决,messages看到有文件系统报错,看起来应该和是网络盘挂载有关,换到本地磁盘后正常

    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626493] ------------[ cut here ]------------
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626500] WARNING: CPU: 2 PID: 813834 at fs/smb/client/file.c:3341 cifs_limit_bvec_subset.constprop.0+0x11a/0x190 [cifs]
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626628] Modules linked in: bluetooth ecdh_generic ecc mptcp_diag vsock_diag tcp_diag udp_diag raw_diag inet_diag unix_diag tls cpuid veth xt_nat xt_tcpudp xt_conntrack nft_chain_nat xt_MASQUERADE nf_nat nf_conntrack_netlink nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 xfrm_user xfrm_algo xt_addrtype nft_compat nf_tables libcrc32c nfnetlink br_netfilter bridge cmac nls_utf8 cifs cifs_arc4 cifs_md4 fscache netfs 8021q garp mrp stp llc overlay vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vsock binfmt_misc intel_rapl_msr nls_iso8859_1 intel_rapl_common intel_pmc_bxt intel_telemetry_pltdrv intel_punit_ipc intel_telemetry_core crct10dif_pclmul polyval_generic ghash_clmulni_intel sha256_ssse3 sha1_ssse3 aesni_intel crypto_simd cryptd vmw_balloon rapl joydev input_leds serio_raw vmw_vmci mac_hid sch_fq_codel vmwgfx drm_ttm_helper ttm drm_kms_helper msr parport_pc ppdev drm lp parport efi_pstore ip_tables x_tables autofs4 hid_generic usbhid crc32_pclmul hid psmouse mptspi mptscsih mptbase ahci
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626752]  vmxnet3 libahci scsi_transport_spi i2c_piix4 pata_acpi
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626761] CPU: 2 PID: 813834 Comm: bash Tainted: G        W          6.5.0-35-generic #35~22.04.1-Ubuntu
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626765] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 12/12/2018
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626768] RIP: 0010:cifs_limit_bvec_subset.constprop.0+0x11a/0x190 [cifs]
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626877] Code: c0 48 29 c2 75 c4 41 89 0b 4c 89 c0 48 8b 5d f8 c9 31 d2 31 c9 31 f6 31 ff 45 31 c0 45 31 c9 45 31 d2 45 31 db c3 cc cc cc cc <0f> 0b 45 31 c0 4c 89 c0 31 d2 31 c9 31 f6 31 ff 45 31 c0 45 31 c9
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626880] RSP: 0018:ffffb1ee12bcbaf8 EFLAGS: 00010297
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626883] RAX: ffff8f2f4face118 RBX: ffff8f2f4face0c0 RCX: 0000000000000000
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626885] RDX: ffffb1ee12bcbb44 RSI: 0000000000000100 RDI: ffff8f2f4face118
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626887] RBP: ffffb1ee12bcbb80 R08: 0000000000000100 R09: 0000000000000000
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626889] R10: 0000000000000000 R11: 0000000000000000 R12: ffff8f2f573b4000
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626890] R13: ffff8f2f53c57c00 R14: 0000000000000100 R15: ffff8f2ec4fb4200
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626892] FS:  000070ff35ade740(0000) GS:ffff8f2ff9d00000(0000) knlGS:0000000000000000
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626895] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626897] CR2: 00005ab2387bd8e0 CR3: 000000011744c000 CR4: 00000000003506e0
    Jun 30 17:52:03 tianlan-ubuntu kernel: [1143203.626908] Call Trace:
    

    小米MIX2s(白)

  • @Ta / 2024-06-30 / /
  • @Ta / 2024-07-01 / /
    @天蓝,sh脚本里你没有写头/bin/bash
    啥的
添加新回复
回复需要登录