r/ScriptSwap • u/YMGenesis • Mar 03 '19
After discovering Linux, it has helped me to start using command-line/scripting more to automate tedious activities I do often. I present my first large-ish script! An interactive SSH configuration tool. Scripting beginner wanting to learn more... go easy on me!
Tried to crosspost from /r/linux, but it wasn't a text post.
Hope some might find this useful!
11
Upvotes
5
u/[deleted] Mar 03 '19
It’s a well made script but you can use ansible playbook to do this as well, it’s simpler and more reliable.
4
u/h2opologod94 Mar 04 '19
Looks good! I'm just on my phone, so I haven't run it, but based on just looking at it, there are a couple suggestions. First, you can run your script through Shellcheck (https://www.shellcheck.net/) to catch a few mistakes or non-idiomatic behavior. Looks like the script tripped a few lints as it is. Second, I would suggest you break your main function down further and have a separate function for each of the menu responses. A last minor point is that you should check the return values of nontrivial external programs (ssh-keygen, ssh-copy-id, etc) instead of proceeding on like they exited cleanly.
Overall, nice work!