问题原文
原帖链接 · Orsiris de Jong · CC BY-SA 3.0
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
Unmatched ".
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.
已采纳解答
原帖链接 · John Sellens · CC BY-SA 3.0
If you simplify your command line, the shell likely won't matter. This should likely work
ssh </some/filelist -i /home/user/.ssh/some_key user@freebsd11 xargs -n 1 stat -f \"%N;%c;%m\" | sort
Alternatively, you may want to change the default shell to bash for the particular user you are ssh-ing to - see the chsh(1) command.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
