I'm searching a way to be sure my commands are executed by bash on some FreeBSD 11 machines that use csh as default shell.
The following is my code that works on Linux CentOS / Debian / MacOS X / pfSense 2.3 (running on FreeBSD 10.3) and even Windows 10 bash, but doesn't work on FreeBSD 11
cat "/some/filelist" | ssh -i "/home/user/.ssh/some_key" user@freebsd11 'bash -c "while read -r file; do stat -f \"%N;%c;%m\" \"\$file\"; done | sort"'
Output of the previous command on FreeBSD 11 seems to be a csh error message
When checking which shell runs, it seems that csh runs. The following returns 'csh'
ssh -i /home/user/.ssh/some_key user@freebsd11 'bash -c "echo $0"'
As of my understandings, BSD systems do not allow changing shell, unless using a heredoc, but I can't send cat "/some/filelist" using a heredoc.
Of course, bash is installed and can be executed. I'm not interested in changing the default shell of the users on FreeBSD.
Any ideas here ?
My best guess would be to divide the problem:
1/ send the file with
cat /some/filelist | ssh [..] 'cat > somefile'
2/ use the sent file in a heredoc
ssh [..] 'bash -s' << 'EOF' while read -r file; do stat -f "%N;%c;%m" "$file" | sort; done < "$somefile" 'EOF'
This solution could work but is messy, makes 2 connections instead of one and won't work if remote can't write the 'somefile' for some reason.