在Red Hat Enterprise Linux 8系统中,检查日志时我们发现了一个错误信息。如何解决修复该问题呢?请继续阅读如下文章。
commvault.Instance001.service: Ignoring invalid environment assignment 'BASH_FUNC_which%%=() { ( alias;': /opt/commvault/Base/Temp/Galaxy.env
先决条件
- Red Hat Enterprise Linux release 8.10 (Ootpa)
- COMMAVAULT 11.20.85
诊断步骤
1.检查rpm软件包
检查包含export-f语句的rpm软件包。
rpm -qf $(grep -l 'export -f' /etc/profile.d/*)
2.检查用户变量
登录到用户账户,查看当前环境变量中是否存在BASH_FUNC_xxx变量。
$ ssh user@localhost user@localhost's password: Last login: Fri Jul 16 20:14:46 2021 from ::1 [user@shizhanxia.com ~]$ env | grep BASH_FUNC_ # 输出类似如下结果为存在该变量 BASH_FUNC_module%%=() { _module_raw "$@" 2>&1 BASH_FUNC__module_raw%%=() { unset _mlshdbg; BASH_FUNC_switchml%%=() { typeset swfound=1; BASH_FUNC_scl%%=() { if [ "$1" = "load" -o "$1" = "unload" ]; then BASH_FUNC_ml%%=() { module ml "$@"
解决方案
为什么会添加一个BASH_FUNC%%_function_name 的变量?
自Bash4.0版本的官方补丁41起,导出函数的编码机制得到了改进。这一改动旨在解决与shell变量之间的潜在冲突,并确保不再仅仅依据环境变量的内容来判定其是否应被解释为shell函数。官方对此提供了如下详细说明:
This patch changes the encoding bash uses for exported functions to avoid clashes with shell variables and to avoid depending only on an environment variable's contents to determine whether or not to interpret it as a shell function.
我们可以采取以下方法解决该问题。
1.取消环境变量
使用unset -f命令取消所有BASH_FUNC_xxx变量。
[user@shizhanxia.com ~]$ unset -f $(env | sed -n -e "s/BASH_FUNC_//;s/%%.*//p")
2.设置用户登录执行
为了确保每次用户登录后都执行此操作,可以在/etc/profile.d/目录中,创建一个类似名为z_shizhanxia.sh的文件,并在其中添加上述unset命令。确保该文件的名称以z_开头,以便它在目录下的其他脚本之后执行。
[user@shizhanxia.com ~]# echo 'unset -f $(env | sed -n -e "s/BASH_FUNC_//;s/%%.*//p")' > /etc/profile.d/z_shizhanxia.sh
注意:在执行此操作之前,请确保了解每个函数的作用,并谨慎选择是否取消设置。
总结扩展
BASH_FUNC_xxx变量常常在安装特定软件包(例如scl-utils和environment-modules)后出现。针对由此引发的问题,我们可以尝试多种解决方案。其中一种有效的方法是删除或备份/etc/profile.d/which2.{sh,csh}文件。特别值得注意的是,从RHEL 8.5版本开始,BASH_FUNC_which%%环境变量正是由这些文件所设置。因此,处理这些文件可能是解决问题的另外一种方法。
技术评审
- 评审专家:保哥 | 某保险公司运维开发工程师
- 验证结论:已在实际生产环境中解决该问题。
修订记录
- 2025-02-08 v1.0 初版发布
原创文章,作者:保哥,如若转载,请注明出处:https://www.shizhanxia.com/2264.html