I use a 3D-printing program that needs several commands run in sequence. The setup currently looks like this:
`sudo chmod 777 /dev/ttyACM0`
`python -m venv venv`
`source venv/bin/activate`
`cd Printrun`
`./pronterface.py`
The `chmod` command asks for an administrator password. Can a shell script handle this safely, and do I need to add delays between commands while each one finishes?
3 Answers
Avoid using `chmod 777` on a device if possible. It gives every local user read, write, and execute permissions, and the execute permission is not normally useful for a serial device. A udev rule can assign the correct ownership or group permissions to `/dev/ttyACM0`, which avoids needing `sudo` whenever the program starts. If you do need an elevated command, `sudo` can prompt in the terminal, while `pkexec` may provide a graphical authentication prompt depending on your system.
Be careful about scripting commands you don't fully understand. `python -m venv venv` creates an isolated Python environment, but it does not install any packages by itself. You may need to activate the environment and install Printrun's dependencies separately. Once the environment is set up, the launcher could change into the program directory, activate the environment, and start `pronterface.py` without recreating everything each time.
A script can run these commands in order, but you generally don't need to add delays. Commands run synchronously unless you explicitly put them in the background. Use `&&` if you want later commands to run only when the previous one succeeds. Also, creating the virtual environment is usually a one-time setup step rather than something to repeat every time you launch the program.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures