I have written a small code snippet to check the aws cli version
#!/bin/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"
Now while running this manually with root user I am able to run but after our aws cli upgrade while running this via crontab
57 21 * * * /rough/scripts/log/test.sh > /rough/scripts/log/test.log 2>&1
I face the below error , can you suggest , i have reinstalled the aws cli but to no effect.
/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!
cron
runtime environment is different. see https://unix.stackexchange.com/questions/673908/why-crontab-doesnt-execute-a-scheduled-bash-script/673918#673918 – waltinator Mar 11 '23 at 00:51PYTHONIOENCODING
for example? – steeldriver Mar 11 '23 at 13:49if
to check two directories that are already in your$PATH
? The whole script looks like it can be simplified to just the single commandaws --version
. Is it that you want to always prioritize the version found in/usr/local/bin/
even if there is another in/usr/bin/
? And why domessage=$(command); echo $message
instead of simply just runningcommand
directly? – terdon Mar 11 '23 at 14:44