Re: [SLUG] better way to consolidate shell commands

From: Eben King (eben1@tampabay.rr.com)
Date: Thu Aug 19 2004 - 16:03:47 EDT


On Thu, 19 Aug 2004, Mike Branda wrote:

> I've been taking advantage of the shared rsa key that Ian set me up with
> a while back for our 122 render nodes that allows me to ssh without a
> pwd to those specific machines. The next step was to create a couple of
> anyscript.sh shell scripts that basically do a given command on all of
> them. for example ( and I know this is very basic so try not to laugh
> too hard.....) -
>
> #! /bin/sh
>
> echo "attempting to ssh 192.168.3.2 as root"
> ssh root@192.168.3.2 "df -h"
> echo "attempting to ssh 192.168.3.3 as root"
> ssh root@192.168.3.3 "df -h"
> echo "attempting to ssh 192.168.3.4 as root"
> ssh root@192.168.3.4 "df -h"
> echo "attempting to ssh 192.168.3.5 as root"
> ssh root@192.168.3.5 "df -h"
> echo "attempting to ssh 192.168.3.6 as root"
> ssh root@192.168.3.6 "df -h"
> echo "attempting to ssh 192.168.3.7 as root"
> ssh root@192.168.3.7 "df -h"
> echo "attempting to ssh 192.168.3.8 as root"
> ssh root@192.168.3.8 "df -h"

Wouldn't it be easier and more understandable to do

#! /bin/sh

for number in `seq 1 123` ; do
  machine=192.168.3.$num
  command='df -h'
  echo attempting to ssh to $machine as root
  ssh root@$machine "$command"
done

? Anyhow, allowing root to ssh in is a bit of a security risk. You don't
know who is doing it; whereas, if you don't allow it and require everyone
to log in and su, you get a log entry something like "session opened for
user root by eben(uid=500)".

> and so on all the way through .123 at the end. If I want to see
> something else I just do a search and replace of whatever is in quotes.
> While this gets the job done, I know that this way is not very efficient
> and it will get worse as more nodes are added. In an effort to learn
> more, can anybody tell me if there's a way to add a variable that
> increases by a factor of 1 until it reaches a certain number (say
> .123)??

It seems I already took care of this. Whoops. So much for listening
before I talk. :-)

> If this could be done, I could just change the stop point for
> the variable. In addition to this does anybody know where any good web
> tutorials are for sh and bash scripting basics??

Hang out in comp.unix.shell. Read what Chris F. A. Johnson writes; he's
good.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar

rm -f /bin/laden

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:00:41 EDT