[raspberry-vi] Re: Auto-start shell/batch scripts on a pi?

  • From: Jacob Kruger <jacob@xxxxxxxxxxxxx>
  • To: raspberry-vi@xxxxxxxxxxxxx
  • Date: Thu, 17 Nov 2016 20:22:27 +0200

Yes, know about including the first line in python scripts:

#!/usr/bin/env python


Just tried it now under vinux VMWare machine here on my windows PC, but, 
issue is just that named file just 1 and, used chmod +x 1 to, in theory 
make it executable, but, if I then just type in 1 and hit enter from 
command line, it seems to just lock up waiting for something - orca just 
tells me there's white space appearing, but, it never executes the 
python code, whereas if I type in python 1 and hit enter, then it runs 
the code.


Could quite easily implement menu systems using python code itself - 
python is one of my sideline focus areas, but, issue is just how to get 
it to launch that script from startup for now - suppose there's the 
equivalent of an autoexec.bat under linux that could add a line to to 
run the script, and, then take it from there?


For example, in terms of running the arecord command, could possibly run 
that in a separate thread under python using the threading module to 
launch a shell command, and, then when the user made another choice from 
a pseudo-menu offered using raw_input() function, then could just 
terminate the thread, which should stop recording, and, then just exit 
the python script, when they could then just power off - or could 
possibly call something like sudo shutdown now from the python script as 
well?


Stay well


Jacob Kruger
Blind Biker
Skype: BlindZA
"Resistance is futile, but, acceptance is versatile..."

On 2016-11-17 7:59 PM, Jeffery Mewtamer wrote:

Bash scripts are the Linux equivalent to batch files, and indeed, they
are named .sh by convention.

The basic structure of a bash script is:
#! /bin/bash
[commands to be executed]

and once saved and made executable, you can run them by typing
path/to/script.sh

at the command line. Do note that you will need to append ./ in front
of the script name to run a script in the working directory. E.g.:
./script.sh

As for python code, if you add
#! /usr/bin/python

or

#! /usr/bin/python3

to the top of a .py source file and make it executable, you can run it
without having to invoke the python or python3 command.

In general, if I'm not mistaken, adding

#! /path/to/interpreter

to the top of a source file and making it executable works for most
interpreted languages.

And while the how is beyond my current knowledge, it is possible to
build bash scripts featuring numbered menus that can be navigated both
with the arrow keys and pressing the number corresponding to menu
options. In fact, I'm fairly certain rassbpi-config is such a script.


=========================================================== 
The raspberry-vi mailing list 
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi 
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and 
attitudes expressed by the subscribers to this list do not reflect those of the 
Foundation.

Mike Ray, list creator, January 2013

Other related posts: