I am trying to run some commands on a remote server using EOF however I see some issues. Please see below
This works:
#!/bin/sh
ssh -4q <some-server> sh <<'EOF'
E_Distro=<somebody>@gmail.com
CONTROLM_FOLDER="/var/opt/bmc_ctm"
COUNTER=$(find $CONTROLM_FOLDER/ -type f -size +50M -exec ls -lrth {} \; | wc -l)
THRESHOLD=20
if [[ $COUNTER != 0 ]]; then
echo -e "something" | mail -s "Test" $E_Distro
fi
EOF
This does not:
ssh -4q <some-server> sh <<EOF
E_Distro=<somebody>@gmail.com
CONTROLM_FOLDER="/var/opt/bmc_ctm"
COUNTER=$(find $CONTROLM_FOLDER/ -type f -size +50M -exec ls -lrth {} \; | wc -l)
THRESHOLD=20
if [[ $COUNTER != 0 ]]; then
echo -e "something" | mail -s "Test" $E_Distro
fi
EOF
I get below error if I use EOF without quotes
~/scripts/mysripts> sh EOF_test.sh
find: ‘/home/admb8rwd0’: Permission denied
find: ‘/home/admb7rpb0/.ssh’: Permission denied
find: ‘/home/admf82nh0’: Permission denied
find: ‘/home/admfpvdh0’: Permission denied
find: ‘/home/admdk35b0/.ssh’: Permission denied
find: ‘/home/admtqw3m0’: Permission denied
find: ‘/home/admfk5rm0’: Permission denied
find: ‘/home/admjxwxb0’: Permission denied
find: ‘/home/admgv1pc0’: Permission denied
find: ‘/home/admfg252b’: Permission denied
find: ‘/home/admgykmq0’: Permission denied
I read online that if we use quotes for EOF token it does not expand variables however I see a reverse behavior here. Please suggest what is correct way to use EOF