0

I have written a small code snippet to check the aws cli version

    #!/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"

Now while running this manually with root user I am able to run this script without any issue . Post our aws cli upgrade when we try to schedule this script via crontab for root user ( schedule given below)

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.

I understand crontab runtime environment is different than when you run a script manually but can I check whats the runtime environment that cronjob picks up. The user is root and OS is SLES.

[[Error as below]]

/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!`
6
  • Wild guess, you're mixing different python versions. Commented Mar 11, 2023 at 13:11
  • @MarcusMüller- I read this somewhere that the python version used by aws cli and the os python version is interdependent , the problem is for all my other servers it works fine having a different awscli python version and os python version. I am struggling to find a clue since yesterday :(
    – AashkaTe
    Commented Mar 11, 2023 at 13:24
  • Saving the output to $message and then echoing it later is dumb. Just run without saving the output unless you're going to use that output. echo is a bit dangerous to just stuff random output on its command line.
    – user10489
    Commented Mar 11, 2023 at 13:36
  • The last line in your output (unicode error) is incomplete. There should be something informative right after that that is the real error. But I'd guess that the input has a malformed unicode entity in it. Without knowing what this is, I can't say if this is a bug in your input or poor error handling in the code. It is possible to tell python how to handle bad unicode so you don't get this error.
    – user10489
    Commented Mar 11, 2023 at 13:40
  • redirect: You're right, I misread that as 2> /dev/null idunno why. Must be asleep.
    – user10489
    Commented Mar 11, 2023 at 13:41

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.