我编写了一个小代码片段来检查 aws cli 版本
#!/usr/bin/env bash
if [ -e "/usr/local/bin/aws" ];
then
myAWS="/usr/local/bin/aws"
else
myAWS="/usr/bin/aws"
fi
myCmd=("${myAWS} --version")
echo "$myCmd"
message=$($myCmd)
echo "$message"
现在,当使用 root 用户手动运行此脚本时,我可以毫无问题地运行此脚本。当我们尝试通过 crontab 为 root 用户安排此脚本时,发布我们的 aws cli 升级(时间表如下)
57 21 * * * /rough/scripts/log/test.sh > /rough/scripts/log/test.log 2>&1
我遇到以下错误,你能建议吗???我已经重新安装了 aws cli 但没有效果。
我知道 crontab 运行时环境与手动运行脚本时不同,但我可以检查 cronjob 选择的运行时环境是什么。用户是root,操作系统是SLES。
[[错误如下]]
/usr/local/bin/aws --version
Traceback (most recent call last):
File "aws", line 19, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 493, in exec_module
File "awscli/clidriver.py", line 43, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 493, in exec_module
File "awscli/help.py", line 20, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 493, in exec_module
File "docutils/core.py", line 23, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 493, in exec_module
File "docutils/io.py", line 43, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 4-6: surrogates not allowed
[24036] Failed to execute script 'aws' due to unhandled exception!`