nick8967
Posts: 73
Joined: Fri Mar 25, 2016 11:02 pm

Autonomous commands execution

Tue Jul 16, 2019 12:10 pm

Hello,

Is there any possibilty to make the Raspberry run commands by itself, without typing commands? What I mean is this: suppose I have a program running in Raspberry Pi 3 B+, and concerning the outputs I take on the terminal I give different commands: do this, do that etc. What I want to achieve is to setup the Raspberry and let it work autonomously and the commands I would give on terminal, to program it in such a way, so that to be executed autonomously.

Thank you...

klricks
Posts: 6510
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Autonomous commands execution

Tue Jul 16, 2019 12:30 pm

Not sure what you are asking?

The xdotool package will allow you to execute keyboard key-press & mouse move/clicks from scripts.

Code: Select all

sudo apt update
sudo apt install xdotool
xdotool -h
man xdotool
or Google for examples.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

nick8967
Posts: 73
Joined: Fri Mar 25, 2016 11:02 pm

Re: Autonomous commands execution

Tue Jul 16, 2019 12:43 pm

For example: I start a program, this program gives me an output on the terminal, then I should give a command as far the output is concerned, the command is executed, the program gives me an output on the terminal, I should give another command, the program gives me another output, then I should give another command, etc until the program finally finishes. This whole procedure I want to take place automatically.

PhatFil
Posts: 1314
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Autonomous commands execution

Tue Jul 16, 2019 1:29 pm

Yes put your commands in a bash script file, make it executable and give permissions to any users that need it.
(GOOGLE/SEARCH 'Make bash script executable Raspberry Pi' )

to schedule your script to run at startup, before shut down, or at a specified time use cron
(GOOGLE/SEARCH 'Raspberry Pi crontab')

to execute your commands conditional on an input or condition write a monitoring program/script containing your logic and use crontab above to schedule it to start with the pi.
(GOOGLE/SEARCH 'Raspberry Pi programming')

PiGraham
Posts: 3568
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Autonomous commands execution

Tue Jul 16, 2019 1:40 pm

nick8967 wrote:
Tue Jul 16, 2019 12:43 pm
For example: I start a program, this program gives me an output on the terminal, then I should give a command as far the output is concerned, the command is executed, the program gives me an output on the terminal, I should give another command, the program gives me another output, then I should give another command, etc until the program finally finishes. This whole procedure I want to take place automatically.
If you know what commands you want to run in what sequence in what situation you can simply put the commands in a shell script. That is you can write a program in script and have it do quite complex things.
Alternatively you can invoke commands from various programming language such as Python and make use of Python libraries and features to work out what commands to run when.

If you are thinking of having the RPi automatically working out for itself what commands to run that takes you into Artificial Intelligence and a different order of complexity.

Andyroo
Posts: 3864
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Autonomous commands execution

Tue Jul 16, 2019 3:49 pm

You may get away with a long series of ‘IF THEN’ statements or a finite state machine.

The hard bit maybe reading the output on the GUI screen - terminal / console output is easier to handle.
Need Pi spray - these things are breeding in my house...

Return to “Troubleshooting”