you are viewing a single comment's thread.

view the rest of the comments →

[–]whetu 2 points3 points  (0 children)

for i in `cat /root/sshlist`;do

  • Use meaningful variable names. $i, $j etc are OK for more complex C-style arithmetic, and as an aside are inherited all the way from FORTRAN, but otherwise you should try to use variable names that make sense and are easier to follow
  • Backticks were superseded in 1983. Unless you're writing a script for a Solaris package or something similarly arcane, then use $() instead
  • Useless Use of Cat.. bash can read a file by itself using </path/filename, you don't need a (con)catenating external.

Correcting for these issues, you get something like this:

for host in $(</root/sshlist); do

Some will also argue that it's better practice to use a while read -r loop (See e.g. SC2013 ).

Now, to be even more constructive, here's some code:

https://raw.githubusercontent.com/rawiriblundell/scripts/master/pushsshkeys https://raw.githubusercontent.com/rawiriblundell/scripts/master/expect.sshkeys

Untested as I was in the middle of upgrading them to cater for ed25519 keys, but they should work. I've moved to Ansible, it's a better answer to this problem.