hmh7
Posts: 1
Joined: Sat Mar 16, 2019 9:22 am

Sending Commands to a raspberry pi

Sat Mar 16, 2019 9:34 am

Hello World,
I wanted to ask if it is possible to send commands to the raspberry pi remotely using python. I did lots of search and couldn't find anything similar to what I want.
I want to send commands such as gweb and mv.
Regards

Andyroo

Re: Sending Commands to a raspberry pi

Sat Mar 16, 2019 12:18 pm

Best thing is to use MQTT to link machines together and have your Python program receive these and act on them - the program can check that the command is in a limited list and ignore those that are not.

Giving anything access (especially root access) to a machine is very dangerous for network security.

A good coverage of Python MQTT is at http://www.steves-internet-guide.com

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Sending Commands to a raspberry pi

Sat Mar 16, 2019 12:19 pm

In brief, and assuming the machine running your python code has ssh client installed:
  • Set up key based login
  • In your code use somthing like

    Code: Select all

    os.system('ssh user@host command')
Arguing with strangers on the internet since 1993.

ghp
Posts: 1517
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Sending Commands to a raspberry pi

Sat Mar 16, 2019 2:22 pm

fabric2 allows to execute commands on a remote machine.
https://pypi.org/project/fabric2

or consider thrift. https://thrift.apache.org/
it allows to execute methods in a remote python (or c, java, ...) application.

Sankalp sharma
Posts: 6
Joined: Sat Mar 16, 2019 5:32 am

Re: Sending Commands to a raspberry pi

Sat Mar 16, 2019 3:15 pm

You can remotely access it by ssh and vnc server and can make changes as well :D as run commands

Return to “Python”