2014-10-01 41 views
-2
  1. I have a bot machine (controlled via mobile device) which connects to the Server and fetch information from it by method os "ssh, shell script, os commands,sql queries etc" than it feed that information over the internet (private)
  2. I want to disallow this multiple connection to the server via the bot machine ONLY.. there are other machine which connects to the server which must not be affected

假设拒绝对特定的主机/ IP

Client A from his mobile acess bot machine (via webpage) than the bot machine connect to server (1st session) now if the process of this connection is 5 minute during this period the bot machine will be creating, quering, deleting, appending, updating etc

in the very mean time of that 5 minute duration (suppose 2min after the 1st session started) Client B from his mobile access bot machine (via webpage) than the bot machine connect to server (2nd session) now it will conflict with the 1st session and create Havoc...

限制

  1. Now first of all i do not want to editing any setting on the SERVER ANY WHAT SO EVER
  2. I do not want to edit the webpage/mobile etc
  3. I already know abt the lock file method of parallel shell script and it is implemented at script level but what abt the OS commands and stuff like that which are not in bash script

我的吼声

平行ssh连接到服务器
+0

没有什么神奇的“操作系统命令和类似的东西”,可以实现你想要做的事情。锁文件似乎是最明显和最简单的事情 – Vorsprung 2014-10-01 08:11:39

+0

因此,简而言之,你是说在SSH会话连接之后检查锁文件?因为它是为了避免并行运行相同的Shell Shell脚本?即使如此,我的下一个问题将是如何判断前一个会话是否被绞死或需要很长时间等等。不知道下一个连接(在挂起的会话之后)将看到锁定文件并且将无法连接到所有连接。 ..如何处理这个问题? – user1486241 2014-10-01 08:30:44

+0

另外你让我错了在限制点三我提到我知道abt锁定方法,并解释它..但我不想在这里使用锁定方法,就像他们在shell脚本..所以我想知道替代方法..当它是一个geniune问题时为什么-1点?还请检查我以前的评论为下一个问题。 – user1486241 2014-10-01 09:27:55

回答

0

我假设你有ssh的帐户单一登录和,这在登录时运行的脚本

到脚本在登录

#!/bin/bash 
LOCK_FILE="/tmp/sshlock" 
trap "rm $LOCK_FILE; exit" SIGHUP SIGINT SIGTERM 

if [ $(((`date +%s` - `stat -L --format %Y $LOCK_FILE`) < (30*60))) ]; then 
    exit 0 
fi 
touch $LOCK_FILE 

当过程的ssh登录添加这样的事情通话结束时,删除$ LOCK_FILE

trap声明是锁定的这样一个重要组成部分,请不要使用它

“30 * 60“是一个30分钟的超时时间,这要归功于这个问题的答案How can I tell if a file is older than 30 minutes from /bin/sh?

+0

这是非常好的解决方案,但我需要对此有一点解释...请解释一下它是如何工作的(我第一次看到陷阱命令)......还请解释是否有问题发生,比如我的第一个ssh会话挂起/花费太多时间比在这种情况下这将如何运作。我也可以杀死与新会议挂起的会话吗?如果是,比如何(请添加代码)?请不要介意我只是想加强它,我对此很新。 – user1486241 2014-10-02 04:36:48

+0

另外它是非常好的解决方案,我想在开始会话时制作脚本A部分和B部分的两部分,A部分将在我们完成所有活动时运行B部分将在末尾运行它是好的或者是否有任何缺陷? – user1486241 2014-10-02 04:39:47

+0

请更新吗? – user1486241 2014-10-03 03:26:43

0

也许尝试使用limits.conf来为用户/组强制实施1次登录的硬限制。

您可能需要定期执行cron作业来检查并删除任何过时的登录。

锁定/互斥锁很难正确并且增加复杂性。 limits.conf中最UNIX/Linux系统的标准功能,应该是更可靠的,强调应该......

类似的问题在这里提出:这里 https://unix.stackexchange.com/questions/127077/number-of-ssh-connections-on-a-single-linux-machine

详情: http://linux.die.net/man/5/limits.conf

+0

我想问问limis.conf解决方案是针对bot还是针对服务器?我们应该在哪里实施?如果服务器比它不可能。如果机器人比它可能,但仅仅是它不是正确的解决方案。但它是在我的情况下是好的解决方案 – user1486241 2014-10-02 04:25:29

+0

这是在服务器上的设置。我将你的'限制#1'解释为不要做每一次登录,而不是在服务器上只做一次。 lockfile解决方案也是对服务器登录脚本的更改,所以它也是服务器端解决方案... – sparx27 2014-10-03 07:25:59

+0

我无法执行limits.conf,因为同时还有很多其他ips登录。我的意思是bot将会已经24/7登录,但许多其他PC也会登录,所以“我认为”limits.conf将禁用所有登录。还想对你说,所有用户远程登录使用的用户/组是共同的和相同的。没有seprate user/grp。 – user1486241 2014-10-04 14:12:09