Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the MD5 of some ears in a Unix box using the fanout command but there are some errors.

My code is:

ears=ear1-ear2
cluster=abc
dmgr=server1
k=$(expr `echo $ears | grep -o "-" | wc -l` + 1)

fanout "$dmgr" " umask 022 ; for k in $(seq 1 $k) ; do for i in $(echo $ears | cut -d'-' -f$k) ; do echo /appl/as/bin/md5 /appl/as/var/spool/ears/${cluster}/$i ; done ; done

The error I am getting is as follows :

ksh: 0403-057 Syntax error at line 2 : `2' is not expected.

and it is unable to reference $i

share|improve this question

closed as unclear what you're asking by Gilles, muru, cuonglm, Archemar, Anthon Oct 1 '15 at 4:49

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
It would be best if you detailed what you want to achieve and what results you expect from that command. – Nasha Sep 30 '15 at 7:27
    
i want to get md5 from a box named server1 – amol singh Sep 30 '15 at 7:29
2  
you've an extra " in your fanout command. please try after correcting it ? – NewLands Sep 30 '15 at 7:39
    
There is no 2 on line 2. Also what you posted lacks a #! line. Post your actual, complete script if you want help. And fix your Shift key. – Gilles Sep 30 '15 at 22:26
    
` for k in $(seq 1 $k) ` not sure, this will do good. – Archemar Oct 1 '15 at 4:33
up vote 1 down vote accepted

The reason it's failing with this error is the interpolation of $(seq 1 $k) inside your fanout command.

Let me explain...

Running seq 1 2 returns this:

1
2

You have that inside double quotes, so the newline is kept as significant text. The fanout command therefore evaluates to this:

fanout server1  'umask 022 ; for k in 1
2 ; do for i in ear2 ; do echo /appl/as/bin/md5 /appl/as/var/spool/ears/abc/ ; done ; done'

Your ksh does not understand the 2 on the second line, so it bails.

You can fix this with the inclusion of xargs, but then you hit a second potential problem where you're using k as a loop counter, but the $k is evaluated before the loop runs. Furthermore, you have a subshell where $ears needs to be evaluated before the script runs but it's used within a loop that changes at runtime.

I've found a man page for fanout but I don't understand why you're running your loop against a single system (server1) when fanout exists to run a command against multiple systems. If you can explain the difference between a server and an ear I might be able to suggest a cleaner piece of code. My first suggestion might be this, though:

ears='ear1,ear2'
cluster=abc
dmgr=server1

fanout "$dmgr" "/appl/as/bin/md5 /appl/as/var/spool/ears/${cluster}/{$ears}"
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.