bash

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

Anacron will not run notifications from python/bash scripts

Anacron will not run notifications from python/bash scripts Question: The basics I am trying to add desktop notifications to some fairly simple scripts running with anacron just to let me know when they are running and when they have finished. For some reason, the scripts DO run, but the notifications never get sent. If I …

Total answers: 1

running shell command in python under git-bash not working well

running shell command in python under git-bash not working well Question: I am using python3 under git-bash environment, and sometimes it does not run shell command well. #!/usr/bin/env python3 import subprocess as sp print("hello") print(sp.getoutput("ls -l")) # This works. print(sp.getoutput("date")) # This hangs and cannot terminate with ctrl-c. This does not happen when running under …

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

Bash – evaluate ENV Variable being stored in a command

Bash – evaluate ENV Variable being stored in a command Question: I want to save a command in a variable like this: [user@smat-jupyterhub-nb-user ~]$ TESTCMD=’python script.py’ [user@smat-jupyterhub-nb-user ~]$ SCRIPT=script.py Running $TESTCMD works fine. But I also want to pass a variable to that command: [user@smat-jupyterhub-nb-user ~]$ TESTCMD2=’python $SCRIPT’ When I run this, I get an …

Total answers: 1

How to emit result in Tekton with python script?

How to emit result in Tekton with python script? Question: I my Tekton pipeline I want to emit a result so that $(results.myresult) can be used in the next pipeline task. The code looks like this: apiVersion: tekton.dev/v1beta1 kind: Task name: foo namespace: bar … spec: results: – name: myresult script: | #!/usr/bin/env bash # …

Total answers: 2

How to change Azure App Service Python version from 3.9.7 to 3.9.12?

How to change Azure App Service Python version from 3.9.7 to 3.9.12? Question: I am trying to deploy an application on Azure App Service. I have created a deployment with Python 3.9.7, but my app needs Python 3.9.12. How do I upgrade python’s version? In Azure App Service > Configuration > General Settings > Python …

Total answers: 2

How to replace a number in a text file using regular expressions

How to replace a number in a text file using regular expressions Question: I have a text document with lots of lines that look something like this: some_string_of_changing_length 1234.56000000 99997.65723122992939764 4.63700 text -d NAME -r I want to go line by line and change only the 4th entry (the number 4.63700 in this example) and …

Total answers: 1

Error in Importing a bash script into a python

Error in Importing a bash script into a python Question: I am trying to create a python script script.py in bash and importing a bash script. #!/usr/bin/env python import os import glob from fnmatch import fnmatch # importing a software python_package = os.system("""#!/path_to_bin/bin/python from __future__ import print_function, division from python_toolbox.toolbox.some_toolbox import run if __name__ == …

Total answers: 1

What's the best way to escape a bash command in python?

What's the best way to escape a bash command in python? Question: I have a function that takes in a command as a string, and runs it on an AWS container using the aws binary. The command adds a few extra symbols before and after the command the user requested to run – I won’t …

Total answers: 1