简体   繁体   中英

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

  1. rsh's over to machine (in this case a machine called uk01ff200)
  2. searches for a directory in machine
  3. then within that directory searches for a files starting with 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. 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). So I dont know where I'm going wrong with my script.

What I would do using a 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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