Here's a very small and basic script that sends commands over SSH to another computer on my network:
#!/bin/python
import sys, os
commands = ""
for i in sys.argv[1:]:
commands += " " + i;
if len(sys.argv) <= 1:
os.system("sshpass -p VerySecrectPassword ssh [email protected]")
else:
os.system("sshpass -p VerySecrectPassword ssh [email protected]" + commands)
Am I being very "Pythonic"? Is it better to use a for loop to join all the commands or the join function?
commands = " ".join(sys.argv[1:])
Personally, I think the for loop reads better, but that's just my opinion and I'm a newbie. Which is considered the better way to do things?
Furthermore:
- Are there any other areas in this script that could be improved?
- Is it a bad idea to store the password in the script (located at /usr/bin)?
Note: This script is stored on a computer where I am the only user (except root).