Run Bash Script Another Server

Posted by psce on Server Fault See other posts from Server Fault or by psce
Published on 2014-08-22T08:18:52Z Indexed on 2014/08/22 10:21 UTC
Read the original article Hit count: 310

Filed under:
|
|

I want to run command one by one, for change the names of the directories on the server.

When I run script, directories renamed in server 1. But, directories are not found in server 2.

What the error could be in the script?

Script;

#!/bin/bash

mach_directory=/home/user/example
erase_dir1=cache
erase_dir2=tmp


for i in {0..10}
do
    user=user
    server=$(ssh $user@server$i hostname)

        ssh $user@$server find $mach_directory -type d -name $erase_dir1 ! -path "*Admin/$erase_dir1*" -print0 | while IFS= read -r -d '' file ; do mv "$file" "${file}_$(date +%d%m%Y)"; done

        ssh $user@$server find $mach_directory -type d -name $erase_dir2 ! -path "*Admin/$erase_dir2*" -print0 | while IFS= read -r -d '' file ; do mv "$file" "${file}_$(date +%d%m%Y)"; done
done

© Server Fault or respective owner

Related posts about ssh

Related posts about bash