I have a server AA and from the shell script have to connect to server BB using ssh. On server BB, I want to check if the given folder is empty or not, if not empty it should remove all files & directories.
But o/p and print commands should be printed on server AA.
Tried with below script but after ssh, the commands are executing on the current server. After SSH, it was displaying nothing. Please help me.
IFS='=' read -r -a param1 <<< "$1"
user=${param1[1]}
IFS='=' read -r -a param2 <<< "$2"
server=${param2[1]}
IFS='=' read -r -a param3 <<< "$3"
folder_path=${param3[1]}
ssh $user@$server <<EOF
echo $(hostname)
if [ -d $folder_path ]
then
{
cd $folder_path
rm -rf $folder_path/*
}
echo "Files under $folder_path has been deleted successfully
exit 0
else
echo "No such file/folder"
exit 1
fi
EOF