Reputation: 4108
I wish to write a simple csh script which loops through all computers in a network and executes a command that is input at the command line
echo -n "Please enter command you would like executed on all computers > \n "
set command = "$<"
say the user enters ls | grep something. How would I then execute this command in the following line? I tried
$command
which works fine for input such as echo "Hello World"
. I get the following error for ls | grep something
ls: |: No such file or directory
ls: grep: No such file or directory
ls: something: No such file or directory
Ideally, I would want to enter several commands at the command line before looping through each computer in the network (which I can already do) and execute. Eg say I wish to copy two different files
sudo cp ./bin/elastix /usr/bin; sudo cp ./lib/transformix /usr/lib
Thanks
Upvotes: 0
Views: 349
Reputation: 18624
loops through all computers in a network and executes a command that is input at the command line
You would be perhaps using ssh so you would do something like:
ssh $hostname "$command"
I'm not a csh user so I may have the syntax wrong. For current machine you may use the eval
shell command that should interpret any command sequences, not only simple commands.
Upvotes: 1