shell

sed shell command into Python script

sed shell command into Python script Question: There is a shell command, I am trying to convert the logic into python. But I don’t know what to do, I need some help with that. shell command is this : cd ../../../tests/src/main/java ls grep -R "@Test" -A 1 | grep void | while read LINE do …

Total answers: 1

Exception Handling with subprocess.run in Python

Exception Handling with subprocess.run in Python Question: I am trying to create a function that can run any shell command and return the stdout of that command, without worrying about any exceptions that could be thrown. When testing the code written below with incorrect commands like xyz testing, I get a FileNotFoundError rather that the …

Total answers: 1

Translate multi-command pipeline bash to python

Translate multi-command pipeline bash to python Question: This is what I have in my bash script: example=$(echo $var | cut -c 40- | sed "/[a-zA-Z0-9]$/!d"). I am trying to translate it to python. In Python, echo $var | cut -c 40- would give print(var[40]). And I know that [a-zA-Z0-9] means any character in the range …

Total answers: 1

Translating Bash to Python

Translating Bash function call to Python Question: I am trying to translate this from Bash to Python: password=$(func_name "${configFile}" "<password" "2") func_name and configFile have been defined earlier in the script. func_name is a function and configFile is a working directory leading to an XML file. But I don’t know what to do with func_name …

Total answers: 1

Trouble understanding Bash and translating to Python

Trouble understanding Bash and translating to Python Question: I am trying to translate this from Bash to Python: export file="${directory}/scrutation_$(date "+%Y%m%d_%H%M%S").log" I know that export sets an environment variable, and that (date "+%Y%m%d_%H%M%S") is strftime("%d/%m/%Y, %H:%M:%S") in Python. This is what I have tried: import os os.environ[file]= f"{directory}/scrutation[strftime("%d/%m/%Y, %H:%M:%S")].log" Is this correct? Asked By: answer007 …

Total answers: 1

Jupyter Notebook "!" command not using Virtual Environment

Jupyter Notebook "!" command not using Virtual Environment Question: As we all know we can use !<command> to ensure the cell runs a terminal command. However if we usepip install lxml it installs lxml in the root python kernel and not the kernel environment that we mention in Jupyter. With !command in jupyter notebook, any …

Total answers: 2

Run node.js in interactive mode in terminal like "python -i …"?

Run node.js in interactive mode in terminal like "python -i …"? Question: Dumb question alert: I know that it is possible to run node.js in interactive mode like "python -i foo.py" where it runs the code in foo.py but then leaves you at the prompt ">>>" to interact, but how do I do it in …

Total answers: 1

Is it possible to loop through a JSON file using shell to call to an API?

Is it possible to loop through a JSON file using shell to call to an API? Question: Wondering if it is possible to take a json file such as: [ { "firstName": "John", "lastName": "Doe", "dob": "1900-01-01", "zipCode": "12345", "subscriberId": "123456789", "policyNumber": "12345" }, { "firstName": "Jane", "lastName": "Doe", "dob": "1900-01-01", "zipCode": "54321", "subscriberId": "987654321", …

Total answers: 2

How do I get variables from a Python script that are visible in the sh script?

How do I get variables from a Python script that are visible in the sh script? Question: I need to send notifications about new ssh connections. I was able to implement this through the sh script. But it is difficult to maintain, I would like to use a python script instead. notify-lo.py #!/usr/bin/env python3 …. …

Total answers: 1

How to get python logging output in shell script

How to get python logging output in shell script Question: I would want to get the stdout of the python file into shell script. I initially used print and it worked fine but it is not working for logging. ab.py import logging logger = logging.getLogger() logging.basicConfig(level=logging.INFO) logging.info(‘2222222222222’) print("111111111111") cd.sh #/bin/bash set -e set -x communities=$(python3 …

Total answers: 2