Run Bash Script Another Server
- by psce
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