vij*_*289 12 command-line bash scripts
我的公司要求我运行一个服务器应用程序,所有用户都可以通过 putty 终端访问它。我想编写一个只应打开 20 个腻子终端的 shell 脚本。如果第 21 个终端打开,那么我想立即关闭该终端。
我怎样才能做到这一点?
请帮我。
Geo*_*sen 24
/etc/sshd_config在服务器端编辑您的并更改行:
#MaxSessions 10
Run Code Online (Sandbox Code Playgroud)
到
MaxSessions 20
Run Code Online (Sandbox Code Playgroud)
见man sshd_config:
MaxSessions
Specifies the maximum number of open shell, login or subsystem
(e.g. sftp) sessions permitted per network connection. Multiple
sessions may be established by clients that support connection
multiplexing. Setting MaxSessions to 1 will effectively disable
session multiplexing, whereas setting it to 0 will prevent all
shell, login and subsystem sessions while still permitting for-
warding. The default is 10.
Run Code Online (Sandbox Code Playgroud)
George 的解决方案运行良好,但是您要求使用 bash 脚本...
因此,当没有诸如MaxSessionsof 之类的选项时,请考虑将其用于其他情况sshd,然后您可以使用以下内容:
if [ "$(pgrep -cx processName)" -gt 20 ]; then pkill -xn processName; fi;
Run Code Online (Sandbox Code Playgroud)
这pkill -n将杀死processName.
这种特殊情况的正确解决方案是乔治的答案。