Skip to content

Commit 22c3088

Browse files
Merge pull request #2587 from Kalivarapubindusree/sshhost
SSH_Host_Script added
2 parents 2effc6e + a8f5b4c commit 22c3088

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

SSH_Host_Script/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SSH_Host_Script
2+
3+
Short description of package/script
4+
5+
- This Script Was simple to setup
6+
- Need import argparse, os
7+
8+
## Setup instructions
9+
10+
Just Need to Import argparse, os then run the SSH_Host_Script.py file and for running python3 is must be installed!
11+
12+
## Detailed explanation of script, if needed
13+
14+
This Script Is Only for SSH_Host_Script use only!

SSH_Host_Script/SSH_Host_Script.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import argparse
2+
import os
3+
4+
SSH_TEMPLATE = """
5+
HOST {name}
6+
HostName {hostname}
7+
User {user}
8+
Port {port}
9+
"""
10+
11+
def args_to_obj(args):
12+
return SSH_TEMPLATE.format(**args.__dict__)
13+
14+
def add_to_conf(conf, obj):
15+
conf = os.path.expanduser(conf)
16+
with open(conf, 'a') as f:
17+
f.write(obj)
18+
19+
def main():
20+
parser = argparse.ArgumentParser(prog="Adds ssh hosts to the ssh config file.")
21+
parser.add_argument('name', help="Name of the Host to add to the config.")
22+
parser.add_argument('hostname', help="Hostname/IP address of the host.")
23+
parser.add_argument('--user', default='root', help="The user to connect with. Defaults to root.")
24+
parser.add_argument('--port', default=22, type=int, help="The port to connect to. Defaults to 22.")
25+
parser.add_argument('--conf', default='~/.ssh/config', help="The path to the ssh config file. Defaults to ~/.ssh/config.")
26+
27+
args = parser.parse_args()
28+
obj = args_to_obj(args)
29+
add_to_conf(args.conf, obj)
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
 (0)