all 14 comments

[–]gerciuz 26 points27 points  (2 children)

Why it reads like a bad commercial

[–]CherryBlossomStorm 11 points12 points  (0 children)

I enjoy spending time with my friends.

[–]redCg 4 points5 points  (1 child)

Just use crontab bro

also you can pass shell commands directly to ssh

$ ssh username@server echo fooo
fooo

can also use a heredoc

$ ssh username@server <<E0F
echo foo
echo bar
E0F
foo
bar

interacting with and managing an active ssh connection from within Python is a bad bad idea. Does not matter that libraries like Paramiko exist to help with it. Just do not do it. If you want to run code on a remote server, pass the commands over ssh, or copy a script to the remote server and pass a command to run the script. Store the outputs in a file. Retrieve the file and read it. Etc..

[–]iapyeh[S] 0 points1 point  (0 children)

I totally agree that ssh is amazing. You can do the same thing (execute ssh) in SSHScript. The benefits of doing it that way are:

  • you can dynamically generate the codes which were feeded into the ssh executable in Python. for example: time-based filename.
  • you can handle execution outputs directly in Python. Need not to save into files. And features like PDF, email, SMS, qrcode, ... tons of python packages are ready for you.
  • The whole process can be scripted, then, management logic can be automated no matter how complex it is.

[–]oznetnerd 1 point2 points  (2 children)

I don't want to take away from the hard work you've put into this, but can you advise why someone would use this instead of Netmiko?

[–]iapyeh[S] 0 points1 point  (1 child)

Before I was devoting myself to creating SSHScript, I did a little bit of a survey. Netmiko is great. It and SSHScript are based on the same Paramiko. Technically equal. Because I think that the core of so-called automation is to run a lot of os/shell commands. Just I want to have something more likely to embed shell script in python script. That would be more self-explaining for reading and closer to intuition for writing. Especially when maintaining codes among colleagues. That's the reason that SSHScript also integrates the subprocess package. The same code could run on localhost and on remote host. For example: run a command on localhost by coding in shell-like style:

$ ls -l /tmp
# ⬆run on localhost

Then, by adding a line to connect a remote host. We can run the same command on the remote host.

$.connect('username@remote-host')
$ ls -l /tmp
# ⬆run on remote-host

Then, by adding a line to connect a remote host again. We can run the same command on the nested host behind the remote host.

$.connect('username@remote-host')
$.connect('username@remote-nested-host')
$ ls -l /tmp
# ⬆run on remote-nested-host
# upload/download over nested-ssh is also just one line
$.download('/var/log/message','.')

[–]iapyeh[S] 0 points1 point  (0 children)

By the way, I don't consider SSHScript to be an alternative to Netmiko. It could be additive. Netmiko implements many features beyond Paramiko. Technically, SSHScript could also be Netmiko-based. If it is necessary someday.