我想写一个简单的 csh 脚本,循环遍历网络中的所有计算机并执行在命令行输入的命令
echo -n "Please enter command you would like executed on all computers > \n "
set command = "$<"
假设用户输入 ls | grep 的东西。我将如何在下一行中执行此命令?我试过
$command
对于 echo "Hello World"
这样的输入效果很好.我收到 ls | 的以下错误grep 一些东西
ls: |: No such file or directory
ls: grep: No such file or directory
ls: something: No such file or directory
理想情况下,我希望在循环遍历网络中的每台计算机(我已经可以这样做)并执行之前在命令行中输入多个命令。例如说我想复制两个不同的文件
sudo cp ./bin/elastix /usr/bin; sudo cp ./lib/transformix /usr/lib
谢谢
最佳答案
loops through all computers in a network and executes a command that is input at the command line
你可能会使用 ssh,所以你会做类似的事情:
ssh $hostname "$command"
我不是 csh 用户,所以我的语法可能有误。对于当前的机器,您可以使用 eval
shell 命令,它应该解释任何命令序列,而不仅仅是简单的命令。
关于linux - 读取用户输入(应该是 linux 命令)并执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15069211/