简体   繁体   English

UNIX中的Bash Shell脚本将rsh传递到另一台计算机并执行命令

[英]Bash Shell script in unix to rsh to another machine and perform command

Im trying to write a script that rsh's over to a unix machine and executes certain commands on certain files 我正在尝试编写一个将rsh移到unix机器上并在某些文件上执行某些命令的脚本

  1. rsh's over to machine (in this case a machine called uk01ff200) rsh已移至计算机(在本例中为名为uk01ff200的计算机)
  2. searches for a directory in machine 在机器中搜索目录
  3. then within that directory searches for a files starting with core 然后在该目录中搜索以core开头的文件
  4. executes a command on those files (if they exist) which then creates new files 在这些文件(如果存在)上执行命令,然后创建新文件

SCRIPT SO FAR: 脚本这么远:

#!/bin/bash 
#
MACHINE=uk01ff200
DIRECTORY=/var/core

rsh $MACHINE "cd /var/core"
for file in `ls -1 core.*`           
do stack_dump $file         
done 

When I do this manually in the shell on the command line it works. 当我在命令行中的Shell中手动执行此操作时,它将起作用。 So if I rsh over to the machine, cd to the directory, then type in the for loop it works (so I know the for loop syntax is correct). 因此,如果我将rsh转到计算机,将cd转到目录,然后键入for循环,则它可以正常工作(因此我知道for循环语法是正确的)。 So I dont know where I'm going wrong with my script. 所以我不知道我的脚本哪里出了问题。

What I would do using a here-document : 我将使用here-document做些什么:

#!/bin/bash 
#
MACHINE=uk01ff200
DIRECTORY=/var/core

rsh $MACHINE bash <<'EOF'
cd /var/core
for file in core.*          
    do stack_dump "$file"         
done
EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM