[SOLVED] BASH while-do script does not execute another script
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
However, a similar line in the called script never produces output at all, so it appears to not be firing. Running the called script directly works fine.
# Run command on multiple hosts (read host from hostlist)
for i in $(cat hostlist);
do
echo $i; ssh -o StrictHostKeyChecking=no -l root $i -C "echo command";
done
100% nothing wrong with the original while read loop
Yours will fail
Code:
# Run command on multiple hosts (read host from hostlist)
for i in $(cat hostlist);
do
echo $i; ssh -o StrictHostKeyChecking=no -l root $i -C "echo command";
done
Since the list is host<space>port
Your for loop is
Code:
for i in host1 port1 host2 port2 host3 port3 ......
Like I said, nothing wrong with the while read in OP.
Problem, as has already been put out there, is likely
Script not executable ( or at least not for the user )
Incorrect/missing shebang ( #!/bin/bash )
Something else....
without seeing the script we don't know if the host and port are in the correct order
Just a guess.. no script to read ...
100% nothing wrong with the original while read loop
Yours will fail
Code:
# Run command on multiple hosts (read host from hostlist)
for i in $(cat hostlist);
do
echo $i; ssh -o StrictHostKeyChecking=no -l root $i -C "echo command";
done
Since the list is host<space>port
Your for loop is
Code:
for i in host1 port1 host2 port2 host3 port3 ......
Like I said, nothing wrong with the while read in OP.
Problem, as has already been put out there, is likely
Script not executable ( or at least not for the user )
Incorrect/missing shebang ( #!/bin/bash )
Something else....
without seeing the script we don't know if the host and port are in the correct order
Just a guess.. no script to read ...
I wrote "something like this" and didn't mean to copy paste it. Just an idea of implementation.
The code I copied is from my notes and is a working way of running commands on multiple server.
However, a similar line in the called script never produces output at all, so it appears to not be firing. Running the called script directly works fine.
What do you mean by "not be firing"? You say the script called directly works fine; so it sounds as if it is executable, but then you make this "not be firing" statement which causes confusion.
How about you go back to the start. You have a script, post it within [code][/code] tags. Show the output from calling the script directly. Explain next, more clearly; what the problem is. Using a term like "not be firing" means nothing helpful. State instead what desired behavior or output you are not attaining.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.