The other node name of a SUN cluster

Hello,

Under ksh I have to run a script on one of the nodes of a Solaris 8 cluster which at some time must execute a command on the alternate node:
# rsh <name> "command"

I have to implement this script on all the clusters of my company (a lot of...).
Fortunately, the names of the two nodes obey the following rule: a common string excepting the last character which is 1 on one node and 2 for the other.
I don't want to read the names of the machines in /etc/hosts which is really a mess on some clusters... (obsolete names etc.)

I thought to the following solution:

  1. Read in a variable the name of the current node (uname ... ?!?)

  2. In the script I added a part that get from the current node name the other node name. From some reason... when I run from the ksh the commands one by one it works fine:

root@carp # X=abc12
root@carp # numofchar=${#X}
root@carp # numofcharminus1=`expr $numofchar "-" 1`
root@carp # Y=`echo "$X" | cut -c1-${numofcharminus1}`
root@carp # Z=`echo "$X" | cut -c${numofchar}`
root@carp # T=`expr 3 "-" $Z`
root@carp # echo $Y$T
abc11

but when I insert them in the script I got error messages like:

Y=`echo "$X" | cut -c1-${numofcharminus1}`
cut - invalid range

T=`expr 3 "-" $Z`
invalid expression

I don't use scripting too often but I can't see what's wrong in my solution... a CR rule/type conversion... I am too tired and I must finish it until tommorow so please can someone help me! Maybe someone forsee another solution?

Regards

Hello,

Under ksh I have to run a script on one of the nodes of a Solaris 8 cluster which at some time must execute a command on the alternate node:
# rsh <name> "command"

I have to implement this script on all the clusters of my company (a lot of...).
Fortunately, the names of the two nodes obey the following rule: a common string excepting the last character which is 1 on one node and 2 for the other.
I don't want to read the names of the machines in /etc/hosts which is really a mess on some clusters... (obsolete names etc.)

I thought to the following solution:

  1. Read in a variable the name of the current node (uname ... ?!?)

  2. In the script I added a part that get from the current node name the other node name. From some reason... when I run from the ksh the commands one by one it works fine:

root@carp # X=abc12
root@carp # numofchar=${#X}
root@carp # numofcharminus1=`expr $numofchar "-" 1`
root@carp # Y=`echo "$X" | cut -c1-${numofcharminus1}`
root@carp # Z=`echo "$X" | cut -c${numofchar}`
root@carp # T=`expr 3 "-" $Z`
root@carp # echo $Y$T
abc11

but when I insert them in the script I got error messages like:

Y=`echo "$X" | cut -c1-${numofcharminus1}`
cut - invalid range

T=`expr 3 "-" $Z`
invalid expression

I don't use scripting too often but I can't see what's wrong in my solution... a CR rule/type conversion... I am too tired and I must finish it until tommorow so please can someone help me! Maybe someone forsee another solution?

Regards

This looks just like this thread. I believe that's against rule #4.

Sorry I had no intention... I am searching desperately an answer to my problem... even it might be easy...

Can you post your script? Just cut-and-paste it. ( Be sure and use code tags. )

Since you are using ksh, you can use this bit:

thishost=$(uname -n)
basehost=${thishost%[0-9]}
thissuffix=${thishost##*[a-z][0-9]}
thatsuffix=$((3-$thissuffix))
thathost=${basehost}${thatsuffix}
echo $thathost

Hope this helps. Pretty much the best that I can think of right now...

Cheers

Duplicate threads have been merged.

If thishost is "a1bc11" then basehost is "abc" and thathost is "abc2"...

I made a small test script - just the same bunch of commands inside a script. I can't remember the error messages exactly and right now I can't connect on that sparcs... when I can log in ... I'll post the entire output...
BTW there is a command to print the both node names like:

#funame -n

Thanks a lot guys!

Don't know how you got that. I ran it on Solaris 5.8, standard ksh and got this:

# thishost=a1bc11
# basehost=${thishost%[0-9]}
# thissuffix=${thishost##*[a-z][0-9]}
# thatsuffix=$((3-$thissuffix))
# thathost=${basehost}${thatsuffix}
# echo $thathost
a1bc12
# thishost=a1bc12
# basehost=${thishost%[0-9]}
# thissuffix=${thishost##*[a-z][0-9]}
# thatsuffix=$((3-$thissuffix))
# thathost=${basehost}${thatsuffix}
# echo $thathost
a1bc11

Just copy & paste...

1st:

root@carp # X=voms21                                  
root@carp # numofchar=${#X}                           
root@carp # numofcharminus1=`expr $numofchar "-" 1`   
root@carp # Y=`echo "$X" | cut -c1-${numofcharminus1}`
root@carp # Z=`echo "$X" | cut -c${numofchar}`        
root@carp # T=`expr 3 "-" $Z`                         
root@carp # echo $Y$T                                 
voms22

2nd:

root@carp # cat modif
numofchar=${#X}
numofcharminus1=`expr $numofchar "-" 1`
Y=`echo "$X" | cut -c1-${numofcharminus1}`
Z=`echo "$X" | cut -c${numofchar}`
T=`expr 3 "-" $Z`
echo $Y$T

root@carp # X=voms21
root@carp # ./modif
cut: invalid range specifier
cut: no list specified
expr: syntax error

root@carp # 

I have tested too and it works fine on our Solaris 5.8! Thanks a lot man! :slight_smile: