Post by spohnz on Jun 9, 2017 9:54:50 GMT -6
So I have this webserver on a raspberry pi I have it is written in Flask and HTML.
I use SSH to log into it and normally start things up. The steps it takes are:
1. open putty <--I am normally on windows otherwise it would be open terminal
2. type in ssh@ipaddress
3. type in pass
4. cd to the webapp drive I have.
5. ls the drive because I don't know the name of the files I need to run half the time.
6. sudo run server.py
7. submit password
I also use the rpi to tweet, monitor several things on the minecraft server and even the minecraft A.I. kate-bot ran from it.
Now with using a higher security server (AWS) other then the cheap GGservers we were using I wanted to find an easier way of running commands and or grabbing log files from the server.
enter Paramiko
para = paranoid
miko = friend
funny huh?
so back to my local pi. I have figured out how to run the webserver with one script:
If you know other ways of using it please post it here.
I use SSH to log into it and normally start things up. The steps it takes are:
1. open putty <--I am normally on windows otherwise it would be open terminal
2. type in ssh@ipaddress
3. type in pass
4. cd to the webapp drive I have.
5. ls the drive because I don't know the name of the files I need to run half the time.
6. sudo run server.py
7. submit password
I also use the rpi to tweet, monitor several things on the minecraft server and even the minecraft A.I. kate-bot ran from it.
Now with using a higher security server (AWS) other then the cheap GGservers we were using I wanted to find an easier way of running commands and or grabbing log files from the server.
enter Paramiko
para = paranoid
miko = friend
funny huh?
so back to my local pi. I have figured out how to run the webserver with one script:
#startWebServer
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.load_system_host_keys()
ssh.connect('192.168.1.12', username='pi', password='password123')
stdin, stdout, stderr = ssh.exec_command('cd ./webapp; sudo python server.py &')
#<--- notice two separate commands on this line separated by ;
stdin.write('password123\n')
#<-- adding my password after a sudo command followed up with a '\n' newline.
ssh.close()
finally:
ssh.close()
There is also a sftp feature with this that I am going to play with but I was excited to discover paramiko for my automation.If you know other ways of using it please post it here.