[Gllug] Daily timed shutdown script
Richard Jones
rich at annexia.org
Fri Jul 27 09:41:37 UTC 2007
On Fri, Jul 27, 2007 at 12:19:52AM +0100, Dylan wrote:
> I've been asked to put together a script which will shut down a server at a
> configurable time each day. So far so good - set up a cron job to check the
> time and halt the machine.
>
> Unfortunately, the machine provides the following services: ftp (vsftp), nfs,
> samba (file and print,) cups, and ssh, along with performing gateway
> functions. Obviously, I would need to check, for each service, whether there
> is an active connection, and delay the shutdown until any such connections
> have terminated.
Strange request, but ...
Finding out if there are active connections is easy for TCP services.
Run:
netstat -n | grep ^tcp | grep ESTABLISHED
If that prints anything then you have active connections. You might
want to grep -v loopback and connections from&to the local host
(you'll need to know its IP address(es)), since you probably don't
care about the server talking to itself.
NFS is a bit trickier because it's generally run over UDP and is
stateless. You can find out about active mounts by using the
showmount command. Unfortunately this doesn't tell you about clients
which are mounting but not using the server, nor about clients which
have "gone away" without unmounting. I don't think there is a general
way to do that. If you can make the clients use NFSv3 over TCP then
you're in a better position.
Not sure what you mean by "gateway functions". Squid and the like
will be caught using the general TCP method above. General routing /
forwarding / NAT services can be difficult to detect. For NAT/masq
there is a command for listing outstanding connections, but it escapes
my man-page fu at the present time. In any case it also doesn't
reliably detect clients which have gone away.
Rich.
--
Richard Jones
Red Hat
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list