1

Alright so, just for a little heads up, I literally just learned what bash script was today. Anyways,

I have this series of voice recognition programs wrote in python, and I wanted to make a voice command that restarted these scripts using a bash shell, because bash and terminal are the controlling units of Ubuntu. Much like command prompt is for windows.

I was wondering if there was a way to create bash files like windows dos files, and if there was a way to stop a python program

  • without harming it, as in safely stop it.
  • restarting that same python program after stopping it.
  • Kudos for telling me how to start it again after a set amount of time.

Any help is appreciated, and like always, is much needed. I know this might go under "stack overflow" but I honestly felt it was more suited here considering that is strictly for command languages, not really scripting languages, and especially Ubuntu user related questions. Once again, thank you.

  • 4
    [so] accepts scripting just fine, provided you actually have a concrete problem (they don't like gimme teh codez questions) – muru Jun 16 '16 at 06:07
  • Well that's particularly what I'm asking for here, I also tried looking everywhere and theres so much possibility that someone would mistakenly flag my question as a duplicate./off topic. So I cam to Ubuntu :D – TheCodingKlam Jun 16 '16 at 15:25

1 Answers1

1

You can create new bash files simply with creating a new file and making it executable.

e.g.

touch simplebash.sh

now add the shebang to the file so it knows in which shell you actually want to run the script.

You can do this with this simple echo forward or just simple edit the file with an editor

echo "#!/bin/bash" > simplebash.sh

Change the permissions so it is executable

chmod a+x simplebash.sh

Now you can start writing your script/commands into the script and run it in the terminal with this.

./simplebash.sh

There are different ways but this is the simpliest. Now stopping your running python script is nothing more then sending the appropriate kill signal.

e.g. kill 15 processname or pid is the soft way to tell the program please stop and clean up after yourself. Those signals are usually handled by the script/program themselve. If it doesn't react to any kind of signal you can send a kill 9 proccess name or pid which is a signal that cannot be caught by the program/script and means as much as terminate it.

muru
  • 197,895
  • 55
  • 485
  • 740
Ziazis
  • 2,174
  • I just realized this, but I could also use break from within the program, but then I would have two instances running instead of it being chronological. Thanks for this though, I'll try it out. – TheCodingKlam Jun 16 '16 at 15:26
  • Ok thanks man, I did this a ton today, so far my gTTS program can log me out of my computer :) Thanks so much. – TheCodingKlam Jun 17 '16 at 00:10