Launching SSH session via python script on raspberry pi -


i'm looking create script in python initiates ssh session server. know has simple process i'm not sure start. ultimate plan automate script run on startup. not sure python best way go know comes preloaded on raspbain pi.

a simple bash script better suited task. possible python, there's no obvious reason make harder necessary.

from write shell script ssh remote machine , execute commands:

#!/bin/bash username=someuser hosts="host1 host2 host3" script="pwd; ls" hostname in ${hosts} ;     ssh -l ${username} ${hostname} "${script}" done 

from how run script @ start (askubuntu):

you need root privileges following. root, open terminal , run command

sudo su 

and command prompt change '#' indicating terminal session has root privileges.

alternative #1. add initscript.

create new script in /etc/init.d/myscript.

vi /etc/init.d/myscript 

(obviously doesn't have called "myscript".) in script, whatever want do. perhaps run script mentioned.

#!/bin/sh  /path/to/my/script.sh 

make executable.

chmod ugo+x /etc/init.d/myscript 

configure init system run script @ startup.

update-rc.d myscript defaults 

alternative #2. add commands /etc/rc.local

vi /etc/rc.local 

with content following.

# script executed @ end of each multiuser runlevel  /path/to/my/script.sh || exit 1   # added me  exit 0 

alternative #3. add upstart job.

create /etc/init/myjob.conf

vi /etc/init/myjob.conf

with content following

description     "my job"  start on startup task exec /path/to/my/script.sh 

depending on ssh connection, if needs stay open on entire time of device, need use more trickery (ssh connections autoclosed after period of inactivity).


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -