3 # Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import samba
.getopt
as options
21 from samba
.net
import Net
23 from samba
.netcmd
import (
27 class cmd_time(Command
):
28 """Retrieve the time on a server.
30 This command returns the date and time of the Active Directory server specified on the command. The server name specified may be the local server or a remote server. If the servername is not specified, the command returns the time and date of the local AD server.
33 samba-tool time samdom.example.com
35 Example1 returns the date and time of the server samdom.example.com.
40 Example2 return the date and time of the local server.
42 synopsis
= "%prog [server-name] [options]"
44 takes_optiongroups
= {
45 "sambaopts": options
.SambaOptions
,
46 "credopts": options
.CredentialsOptions
,
47 "versionopts": options
.VersionOptions
,
50 takes_args
= ["server_name?"]
52 def run(self
, server_name
=None, credopts
=None, sambaopts
=None,
54 lp
= sambaopts
.get_loadparm()
55 creds
= credopts
.get_credentials(lp
, fallback_machine
=True)
56 net
= Net(creds
, lp
, server
=credopts
.ipaddress
)
57 if server_name
is None:
58 server_name
= common
.netcmd_dnsname(lp
)
59 self
.outf
.write(net
.time(server_name
)+"\n")