0

I'm currently writing a python script on a centos 7 VM which has to execute a couple shell commands along the way. I found a library which does the job, but I'm getting an error on one of them. I was given those commands from a text file so I don't actually know what they do. I understand simple ones, but these are above my level. Since only 2 lines get an error, I know it's not the script itself, but rather how I use it. ./linkerd is linkerd's binary file while linkerd_images.txt has a list of images:

./linkerd install --ha --ignore-cluster | grep image: | grep linkerd | sed -e 's/^ .*images: //' | sort | uniq >> linkerd_images.txt
./linkerd viz install --ha --skip-checks | grep images: | sed -e 's/^ .*images: //' | sort | uniq >> linkerd_images.txt

I do realize that since they use linkerd's binary, they might be unique to the application. If that's the case, then I'll have to figure out where I can find the documentation since I couldn't find it on their repo (hence why I came here first)

Edit: Here's the error I got in the script:

UnicodeDecodeError: 'utf-8' codec: can't decode byte 0xe2 in position 49: Invalid continuation byte

If I run the first command by itself in terminal, I get:

sed: -e expression #1, char 1: unknown command: '[Question Mark Symbol]'

I'm not so much worried about the error itself as I'm not really expecting a direct answer to my python code. I would just like to understand what the commands themselves do with all the fancy characters.

I have been asked to add the python code. I used asyncio's run function to run most of the shell commands. So the python code itself is simply:

asyncio.run(run(
     """./linkerd install --ha --ignore-cluster | grep image: | grep linkerd | sed -e 's/^ .*images: //' | sort | uniq >> linkerd_images.txt"""))

I also checked the linkerd binary file and it does look like a json file.

10
  • We can't help understand an error if you don't tell us what error you get.
    – terdon
    Jun 21, 2021 at 18:27
  • I added the errors I get both when I run the script and when I run the commands by themselves in terminal
    – BloodLord
    Jun 21, 2021 at 18:36
  • sed -e 's/^ .*images: //* looks like it is missing a closing single quote. If those two commands are exactly what you used, try fixing that first?
    – dhag
    Jun 21, 2021 at 19:52
  • 1
    Does the two linkerd commands output JSON documents? Why are you in that case trying to parse them with grep and sed? Would it not be easier to do that with a JSON parser like jq (or a JSON parser library in your Python code)? Would you be able to post the actual output of these two commands? Also, since you call these commands from Python (right?), it would be helpful to see the actual Python code.
    – Kusalananda
    Jun 21, 2021 at 20:01
  • 1
    Next step is to take apart the pipeline. If the error is in the sed command, save the output that is fed to the sed part, have a close look at it, and try to reduce it until you find the part that causes the error.
    – dirkt
    Jun 21, 2021 at 21:27

1 Answer 1

1

Here's the answer I found

The problem was not the caret, but rather the apostrophe. The person who gave me the command typed it with a French keyboard. Since it's on my work PC, I typed it here by looking at my other screen so I retyped a proper apostrophe without thinking about it. Now that I have looked into sed's errors and what they mean, it makes a lot more sense. sed -e expression #1 is the first word after -e (in this case 's/^). Char #1 would be ' which is where I should've initially looked if I had known about it beforehand.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .