我在这样的 bash 脚本中有一个小函数,
func()
{
local nice_val="$NICE -n -19"
/* bunch of if/else statements and some loops*/
$nice_val $NOHUP a.out >> $log_file 2>&1 &
}
当我尝试执行这个文件时,我看到了这个错误。/root/bringup.sh:第 323 行:/usr/bin/nice -n -19:没有这样的文件或目录
以下是我验证的几件事,
- 是的,不错的可执行文件在 /usr/bin/nice 中退出
- 我的 $PATH 还包含 /usr/bin/
- 检查我是否缺少任何库,我不认为我是。
root@dg:~# ldd /usr/bin/nice
linux-vdso.so.1 (0x00007ffdc4dab000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f749b9bf000)
/lib64/ld-linux-x86-64.so.2 (0x00007f749bf67000)
root@dg:~# find / -name libc.so.6
/lib/x86_64-linux-gnu/libc.so.6
注意:1.我以 root 和 $NICE 身份运行所有内容,$NOHUP 是在脚本开头获取源(使用“源”)的一些 shell 变量。2.这个脚本被另一个脚本调用 3.我在网上阅读了清除哈希(hash -r)如果我的“nice”被移动但没有帮助可能会有所帮助。4. 所有这些脚本都在一个容器内运行。但我想这应该不会影响任何事情。
在上面的代码片段中,如果我将 $nice_val 替换为“nice”的完整路径,它就可以工作。ie
/usr/bin/nice -n -19 $NOHUP a.out >> $log_file 2>&1 &
---> 令人惊讶的是,这行得通。哦,我检查了我是否有任何额外的空格,/r's。我没有看到任何这些。
我真的无法理解出了什么问题。非常感谢您对此问题的任何见解。非常感谢。
更新:这是我的代码的问题:(这是重现问题的浓缩虚拟代码)文件 1:bringup.sh
#! /bin/bash
declare -r NOHUP="/usr/bin/nohup"
declare -r NICE="/usr/bin/nice"
declare -r CAT="/bin/cat"
log_file="/root/affinity/dumplog"
values_file="/root/affinity/values"
niceval="$NICE -n -10"
get_indexed_val()
{
local val=$1
if [ -e $values_file ]; then
local val_str=$($CAT $values_file)
IFS=','
read -ra cpu_array <<< "$val_str"
#
# If you uncomment the below line(setting back the IFS to 'space', code works fine.
#
#IFS=' '
return ${cpu_array[$val]}
fi
return 0
}
index=0
for (( index=0; index < 4; index++ )); do
get_indexed_val $index
myval=$?
$niceval $NOHUP /root/affinity/loop.sh $myval >> $log_file 2>&1 &
done
文件 2:loop.sh
#! /bin/bash
i=0
number=$1
while [ $i -lt $number ]; do
sleep 0.1
done
文件 3:价值观
140,150,160,170
如果您不重置 IFS,您将看到的错误消息。
./bringup.sh: line 28: /usr/bin/nice -n -10: No such file or directory
./bringup.sh: line 28: /usr/bin/nice -n -10: No such file or directory
./bringup.sh: line 28: /usr/bin/nice -n -10: No such file or directory
./bringup.sh: line 28: /usr/bin/nice -n -10: No such file or directory
谢谢你们。非常感激。