Hi,<\/p>\n
I have the below code which runs on Server A, connects to a set of Servers, loops through the set of servers and gets IP addresses in range of 10.42.8 from it, then goes into each server in the IP and runs TSSI command.<\/p>\n
function findworkers ()\n {\n knsw=$(kubectl get nodes -A -o name | grep worker)\n\n for knodew in $knsw;\n do\n podres=$( echo $knodew | cut -c 6- )\n echo \"IP Addresses Found in $podres\"\n ssh -q $podres arp -n | grep 10.42.8 | grep ether | awk '{print $1}'\n for rruaddr in $(ssh -q $podres arp -n | grep 10.42.8 | grep ether | awk '{print $1}')\n do\n ssh -q $podres ssh -q $rruaddr tssi\n done\n done\n}\n<\/code><\/pre>\n
Advertisement
Which gives the below output.<\/p>\n
IP Addresses Found in bai-ran-cluster-worker1\n10.42.8.11\n10.42.8.3\nsh: tssi: not found\nsh: tssi: not found\n\nIP Addresses Found in bai-ran-cluster-worker2\n10.42.8.30\n10.42.8.24\nTX 1 TSSI: 23.3428 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: 22.8387 dBm\nTX 4 TSSI: -inf dBm\nTX 1 TSSI: -8.8506 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: -10.0684 dBm\nTX 4 TSSI: -inf dBm\n<\/code><\/pre>\nAs seen above what happens is it returns the result of TSSI command all together for all the IP addresses found.<\/p>\n
I’m unable to figure out how to run TSSI for each IP so the expected output is<\/p>\n
IP Addresses Found in bai-ran-cluster-worker2\n10.42.8.30\nTX 1 TSSI: 23.3428 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: 22.8387 dBm\nTX 4 TSSI: -inf dBm\n\n10.42.8.24\nTX 1 TSSI: -8.8506 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: -10.0684 dBm\nTX 4 TSSI: -inf dBm\n<\/code><\/pre>\nConnection is as follows :<\/p>\n
\n- Server A (Single Server) - Can connect to Server B Set only<\/li>\n
- Server B Set (6 servers ) - Can connect to Server A and Server C Set<\/li>\n
- Server C Set (5-6 servers connected to each Server in Server B set) - Can connect to Server C Set, and cannot connect to Server A.<\/li>\n<\/ul>\n
So the command ssh -q $podres ssh -q $rruaddr<\/code> is for Server A to access each server in Server B Set and then access each server in Server C set and get the results.<\/p>\nAny thoughts on how to write this loop with the expected output ?<\/p>","upvoteCount":1,"answerCount":4,"datePublished":"2024-09-22T13:23:47.916Z","author":{"@type":"Person","name":"tryllz","url":"https://community.spiceworks.com/u/tryllz"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi,<\/p>\n
I have the below code which runs on Server A, connects to a set of Servers, loops through the set of servers and gets IP addresses in range of 10.42.8 from it, then goes into each server in the IP and runs TSSI command.<\/p>\n
function findworkers ()\n {\n knsw=$(kubectl get nodes -A -o name | grep worker)\n\n for knodew in $knsw;\n do\n podres=$( echo $knodew | cut -c 6- )\n echo \"IP Addresses Found in $podres\"\n ssh -q $podres arp -n | grep 10.42.8 | grep ether | awk '{print $1}'\n for rruaddr in $(ssh -q $podres arp -n | grep 10.42.8 | grep ether | awk '{print $1}')\n do\n ssh -q $podres ssh -q $rruaddr tssi\n done\n done\n}\n<\/code><\/pre>\nWhich gives the below output.<\/p>\n
IP Addresses Found in bai-ran-cluster-worker1\n10.42.8.11\n10.42.8.3\nsh: tssi: not found\nsh: tssi: not found\n\nIP Addresses Found in bai-ran-cluster-worker2\n10.42.8.30\n10.42.8.24\nTX 1 TSSI: 23.3428 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: 22.8387 dBm\nTX 4 TSSI: -inf dBm\nTX 1 TSSI: -8.8506 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: -10.0684 dBm\nTX 4 TSSI: -inf dBm\n<\/code><\/pre>\nAs seen above what happens is it returns the result of TSSI command all together for all the IP addresses found.<\/p>\n
I’m unable to figure out how to run TSSI for each IP so the expected output is<\/p>\n
IP Addresses Found in bai-ran-cluster-worker2\n10.42.8.30\nTX 1 TSSI: 23.3428 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: 22.8387 dBm\nTX 4 TSSI: -inf dBm\n\n10.42.8.24\nTX 1 TSSI: -8.8506 dBm\nTX 2 TSSI: -inf dBm\nTX 3 TSSI: -10.0684 dBm\nTX 4 TSSI: -inf dBm\n<\/code><\/pre>\nConnection is as follows :<\/p>\n
\n- Server A (Single Server) - Can connect to Server B Set only<\/li>\n
- Server B Set (6 servers ) - Can connect to Server A and Server C Set<\/li>\n
- Server C Set (5-6 servers connected to each Server in Server B set) - Can connect to Server C Set, and cannot connect to Server A.<\/li>\n<\/ul>\n
So the command ssh -q $podres ssh -q $rruaddr<\/code> is for Server A to access each server in Server B Set and then access each server in Server C set and get the results.<\/p>\nAny thoughts on how to write this loop with the expected output ?<\/p>","upvoteCount":1,"datePublished":"2024-09-22T13:23:47.990Z","url":"https://community.spiceworks.com/t/bash-scripting-loop-issue/1120668/1","author":{"@type":"Person","name":"tryllz","url":"https://community.spiceworks.com/u/tryllz"}},{"@type":"Answer","text":"
Try using the full path name to the “tssi” command.<\/p>\n
Or possibly replace<\/p>\n
\nssh -q $rruaddr tssi\n\n\nwith\n<\/code><\/pre>\nssh -q $rruaddr $(which tssi)<\/p>\n
<\/code><\/pre>","upvoteCount":1,"datePublished":"2024-09-24T00:07:03.521Z","url":"https://community.spiceworks.com/t/bash-scripting-loop-issue/1120668/2","author":{"@type":"Person","name":"pigdog","url":"https://community.spiceworks.com/u/pigdog"}},{"@type":"Answer","text":"couldn’t this be problematic if there is more than one tssi command? Like perhaps, one in /bin/tssi and one in /usr/bin/tssi? Or, archive copies in the system?<\/p>","upvoteCount":1,"datePublished":"2024-09-24T18:45:55.524Z","url":"https://community.spiceworks.com/t/bash-scripting-loop-issue/1120668/3","author":{"@type":"Person","name":"jessevas","url":"https://community.spiceworks.com/u/jessevas"}},{"@type":"Answer","text":"
It shouldn’t be problematic, but it might not work at all.<\/p>\n
“which” will only return a command that is found in the current environment and I think it works via the setting of the PATH variable.<\/p>\n
The \" -a \" option to “which” would return all “tssi” commands found in the environment. So if tryllz’s script isn’t finding it, the output of “which” (if any) is probably not going to be helpful.<\/p>\n
“locate” or “find” is probably the better path for the issue with the 10.42.8.11 and .3 hosts.<\/p>\n
It might even be that “tssi” is not installed on the host(s) with the problem.<\/p>","upvoteCount":1,"datePublished":"2024-09-25T16:54:54.134Z","url":"https://community.spiceworks.com/t/bash-scripting-loop-issue/1120668/4","author":{"@type":"Person","name":"pigdog","url":"https://community.spiceworks.com/u/pigdog"}}]}}