Welcome to the Linux Foundation Forum!

while loop doesnt work on remote ssh linux

robertkwild
robertkwild Posts: 1
edited January 5 in Command Line/Scripting

hi all,

made a simple bash script to check md5 checksums on files on every folder and to save the output to txt documents

#!/bin/bash
#
mnt=/rkw
ssh 172.17.1.3 << EOF
ls $mnt > $mnt/dirs.txt
sed -i 's/dirs.txt//g' $mnt/dirs.txt
sed -i '/^$/d' $mnt/dirs.txt

while read line; do find "$mnt/$line" -type f -exec md5sum {} + > "$mnt/$line.txt"; done < "$mnt/dirs.txt"
EOF

if i comment out the lines
ssh 172.17.1.3 << EOF
EOF

it works fine on my local linux pc

ls /rkw/
dirs.txt  test  test.txt
root@ubuntu:/tmp# cat /rkw/dirs.txt
test
root@ubuntu:/tmp# cat /rkw/test.txt
76bb05fdda93a6a1820f0724afe725ba  /rkw/test/w11x64_24H2.iso
530ba753f43eb3b2db6a3ef1a508d019  /rkw/test/Rocky-9.4-x86_64-minimal.iso

but as soon as i uncomment out the ssh lines and run on my remote linux it doesnt work

ls /rkw/
dirs.txt  test
root@ubuntu02:~# cat /rkw/dirs.txt
test

any help would be much appreciated

thanks,
rob

Categories

Upcoming Training