Here is the context of the question:
So that I can print documents at work, I need to copy the file to another computer and then print from this computer. (Don't ask, it's complicated, and there is no other viable solution.) Both computers are Linux, and I work in bash. The way I'm currently doing this is I scp file to a print computer, and then ssh and print from the command line.
Here is what I would like to do:
To make my life a little easier, I would like to combine these two steps into one. I could easily write a function that performed both of these actions, but I would have to provide my password twice. Is there a way to combine the steps so that I only provide the password once?
Before anyone tells you this, ssh-logins based keys are not an option. This has been specifically disabled by administrators for security reasons.
Decision:
What I ended up with was a modification of the second solution provided by Wrikken. Simply completing the first sentence in a function would do the job, but I liked the idea of ββprinting multiple documents without entering a password once per document. I have a rather long password, and I'm a lazy driver :)
So, I made some commands and wrapped them in a python script. I used python because I wanted to parameterize a script, and I find it easiest in python. I cheated and just ran bash commands from python via os.system. Python simply handled parameterization and flow control. The logic was as follows:
if socket does not exist: run bash command to create socket with timeout copy file using the created socket ssh command to print using socket
In addition to using a timeout, I also added an option to my python script to manually close the socket if I wanted to do this.
If anyone needs the code, just let me know and I will either paste it into the trash or put it in my git repository.
cledoux
source share