我也在 super 用户(这里是https://superuser.com/questions/1425657/identical-scripts-same-permissions-one-hangs-one-doesnt-how-why)上发布了此问题。请在您认为最适合该问题的网站上回答。这将帮助我了解应该使用哪个站点。谢谢。
我总是忘了inxi
命令的名称,所以不久前我创建了一个名为sysinfo-
的bash脚本(请注意最后的“-”,以区分我的脚本与linux命令sysinfo。)
$ cat ~/scripts/sysinfo-
#!/bin/bash
# DESCRIPTION
#
# Display system info at the command promp
#
# Main Program
echo -e "#############\n# inxi -b #\n#############\n"
/usr/bin/inxi -b
echo -e "############"
当我升级系统并将inxi升级到版本3.0.27时,此脚本停止工作
脚本到达inxi命令后挂起,必须使用CTRL + C终止
inxi的开发人员建议我将其升级到版本3.0.33。不幸的是,运行原始脚本时,升级并没有改变结果。但是,经过一些测试后,我发现我无法解释的内容:如果原始脚本不正确,我的脚本的精确副本可以成功运行!
jesse@Limbo ~ $ ~/scripts/sysinfo-
#############
# inxi -b #
#############
^C
jesse@Limbo ~ $ cat ~/scripts/sysinfo- > /tmp/inxi.test
jesse@Limbo ~ $ chmod +x /tmp/inxi.test
jesse@Limbo ~ $ /tmp/inxi.test
#############
# inxi -b #
#############
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 3879 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.32 TiB (57.7%)
Info: Processes: 316 Uptime: 56m Memory: 31.34 GiB used: 4.80 GiB (15.3%) Shell: inxi.test inxi: 3.0.33
############
jesse@Limbo ~ $ diff ~/scripts/sysinfo- /tmp/inxi.test
jesse@Limbo ~ $ ls -l ~/scripts/sysinfo- /tmp/inxi.test
-rwxr-x--- 1 jesse jesse 187 Apr 15 18:46 /home/jesse/scripts/sysinfo-
-rwxr-x--- 1 jesse jesse 187 Apr 15 19:09 /tmp/inxi.test
jesse@Limbo ~ $ md5sum ~/scripts/sysinfo- /tmp/inxi.test
a1356223d7bacb6d5b6d74cf44d733f2 /home/jesse/scripts/sysinfo-
a1356223d7bacb6d5b6d74cf44d733f2 /tmp/inxi.test
这怎么可能?
如果是原始文件的某种损坏,差异将不会被拿走吗?我将如何检查?
是否有可能因为我尚未创建某种策略文件而自动创建了某种策略文件,从而阻止了
inxi
在~/scripts
中的脚本中运行?BIGO!
jesse@Limbo ~ $ mv /tmp/inxi.test ~/scripts/
jesse@Limbo ~ $ ~/scripts/inxi.test
#############
# inxi -b #
#############
^C
也许这可能是一项批准政策?
jesse@Limbo ~ $ apparmor_status | grep inxi
没有结果。
我尝试将
env
放在~/scripts/sysinfo-
和/tmp/inxi.test
中#!/bin/bash
# DESCRIPTION
#
# Display system info at the command promp
#
env
# Main Program
echo -e "#############\n# inxi -b #\n#############\n"
/usr/bin/inxi -b
echo -e "############"
但是两个脚本的
env
输出相同。jesse@Limbo ~ $ diff ~/scripts/sysinfo- /tmp/inxi.test
jesse@Limbo ~ $ ~/scripts/sysinfo- > /tmp/sysinfo.output
^C
jesse@Limbo ~ $ /tmp/inxi.test > /tmp/inxi.test.output
jesse@Limbo ~ $ diff /tmp/sysinfo.output /tmp/inxi.test.output
61a62,75
> System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
> Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
> Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
> date: 02/22/2014
> CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 1355 MHz min/max: 800/4000 MHz
> Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
> Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
> resolution: 1920x1080~60Hz, 1280x1024~60Hz
> OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
> Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
> Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
> Drives: Local Storage: total: 14.44 TiB used: 8.32 TiB (57.7%)
> Info: Processes: 315 Uptime: 1h 40m Memory: 31.34 GiB used: 4.97 GiB (15.9%) Shell: inxi.test inxi: 3.0.33
> ############
如您所见,这不是从
~/scripts
运行bash脚本的问题,而仅是从inxi
中的脚本运行~/scripts
的问题~/scripts
恰好是我系统上的绑定(bind)安装目录。也许那是问题所在?答对了!!
jesse@Limbo ~ $ mv ~/scripts/sysinfo- ~/
jesse@Limbo ~ $ ~/sysinfo-
#############
# inxi -b #
#############
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 900 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.33 TiB (57.7%)
Info: Processes: 322 Uptime: 1h 52m Memory: 31.34 GiB used: 5.36 GiB (17.1%) Shell: sysinfo- inxi: 3.0.33
############
但是等等...
jesse@Limbo ~ $ mv ~/sysinfo- ~/scripts/
jesse@Limbo ~ $ cp ~/scripts/sysinfo- ~/
jesse@Limbo ~ $ chmod +x ~/sysinfo-
jesse@Limbo ~ $ ~/sysinfo-
#############
# inxi -b #
#############
^C
嗯????
我将脚本移回绑定(bind)安装的
~/scripts
目录,然后将其复制(而不是移动)到~/
,使新文件可执行,然后... inxi
挂起!当然,此行为一定是由于某处能够分辨出移动文件和复制文件之间的差异而引起的。程序从bash脚本而不是命令行运行。除了apparmor还能做到这一点吗?
jesse@Limbo ~ $ cd ~/scripts/
jesse@Limbo ~/scripts $ inxi -b
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 1500 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.33 TiB (57.7%)
Info: Processes: 315 Uptime: 2h 01m Memory: 31.34 GiB used: 4.96 GiB (15.8%) Shell: bash inxi: 3.0.33
我看不到目录权限如何产生作用
jesse@Limbo ~/scripts $ ls -ld /tmp/ ~/scripts/ ~/
drwxr-x--- 194 jesse jesse 20480 Apr 15 20:06 /home/jesse/
drwxrwx--- 18 jesse jesse 12288 Apr 15 20:06 /home/jesse/scripts/
drwxrwxrwt 20 root root 24576 Apr 15 20:32 /tmp/
最佳答案
是否有人发现过dmidecode,lshw,lspci,lsusb,lsblk或blkid实用程序,试图回调parent_script?否。因此,任何UNIX或Linux实用程序都会回调parent_script。不。惊喜,惊喜,惊喜,新的inxi版本都可以。
inxi开发人员认为,在不对parent_script有任何深入了解的情况下,对parent_script进行回调是完全正常的。常识是,除非您对脚本及其工作方式有一定的了解,否则永远不要对parent_script进行回调。您只是在要求一个恶性的递归循环。如果恶性循环的运行时间足够长,则可能会填满Linux proc表或耗尽所有可用内存。 inxi开发人员使用非常错误的假设对inxi进行了根本性的更改,并创建了此方案。
以前的2.x版本的inxi从未对parent_script执行过回调。我可以想象很多用户或系统管理员每月都在使用inxi实用程序来帮助记录他们的服务器。而且,使用inxi 2.x可以为他们正常工作。
inxi实用程序的3.x版本更改了基本行为。现在,inxi将执行对parent_script --version的调用。 inxi开发人员假定parent_script将对--version参数作出相应的响应。为什么inxi基本行为的2.x版本没有这样做时,有人会期望--version回调?对于cronjob脚本,这可能非常讨厌。
3.x版本具有非常根本的变化,它将通过恶性递归循环使许多用户措手不及。我试图让inxi开发人员解释为什么他会更改现有的基本行为,以及parent_script --version提供什么有用的目的。祝你好运得到答案。
如何重现问题
在我的示例中,/home/temp/bin目录位于我的PATH中。
将此简单的“dltest”脚本放在您的PATH目录之一中,它将重现该问题:
# cat dltest
#!/bin/bash
# Open another terminal and use ps -ft /dev/pts/? to view the spawned process.
echo -e "\nUsing `tty`.\nSleeping yawn. Taking five seconds...\n" ; sleep 5
echo -e "\nStarting inxi -Ixxx\n"
# for a test use a very basic inxi.
/usr/bin/inxi -Ixxx
$ pwd
/home/temp/bin
$
$ ./dltest
Using /dev/pts/0.
Sleeping yawn. Taking five seconds...
Starting inxi_3.0.32
Concurrently using another terminal:
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13068 1820 0 14:28 pts/0 00:00:00 /bin/bash ./dltest
temp 13070 13068 0 14:28 pts/0 00:00:00 sleep 5
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13068 1820 0 14:28 pts/0 00:00:00 /bin/bash ./dltest
temp 13072 13068 18 14:29 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi
temp 13081 13072 0 14:29 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13082 13081 0 14:29 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13084 13082 0 14:29 pts/0 00:00:00 sleep 5
# The longer it runs the deeper it will get.
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13622 1820 0 14:48 pts/0 00:00:00 /bin/bash ./dltest
temp 13625 13622 1 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13634 13625 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13635 13634 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13638 13635 1 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13647 13638 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13648 13647 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13652 13648 2 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13661 13652 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13662 13661 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13665 13662 20 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13674 13665 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13675 13674 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13677 13675 0 14:48 pts/0 00:00:00 sleep 5
temp@lm19:~$
为了防止这种恶性循环,您可以在脚本顶部添加此替代方法。
if [[ "${1}" == "--version" ]] ; then
# work around for inxi_3.0.32 parent --version anomaly
exit 1
fi