大网数据广告活动
服务器运维问答

Using bash shell when logging into FreeBSD ssh

· 52CE 我爱测

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 1…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。