summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-05-26 02:04:00 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-05-26 02:04:00 +0200
commitc17166fb3d9260d0c02e3f9f559413acde5ce048 (patch)
tree60f5a354e5e257df958dd29c5e5169a0b40627c9
parentd9a6f04ddd8074c36fc8073ec9bd183438801817 (diff)
downloadsamba-c17166fb3d9260d0c02e3f9f559413acde5ce048.tar.gz
samba-c17166fb3d9260d0c02e3f9f559413acde5ce048.tar.bz2
samba-c17166fb3d9260d0c02e3f9f559413acde5ce048.zip
Convert smbstatus to Python.
(This used to be commit f14ad6cd92227c7ed5c570b581e5db82b7d42e25)
-rwxr-xr-xsource4/scripting/bin/smbstatus159
1 files changed, 63 insertions, 96 deletions
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus
index 4dfc3365a1..782e83e4cf 100755
--- a/source4/scripting/bin/smbstatus
+++ b/source4/scripting/bin/smbstatus
@@ -1,96 +1,63 @@
-#!/bin/sh
-exec smbscript "$0" ${1+"$@"}
-/*
- provide information on connected users and open files
- Copyright Andrew Tridgell 2005
- Released under the GNU GPL version 3 or later
-*/
-
-libinclude("base.js");
-libinclude("management.js");
-
-var options = new Object();
-
-options = GetOptions(ARGV,
- "POPT_AUTOHELP",
- "POPT_COMMON_SAMBA",
- "POPT_COMMON_VERSION",
- "nbt");
-if (options == undefined) {
- println("Failed to parse options: " + options.ERROR);
- return -1;
-}
-
-/*
- show open sessions
-*/
-function show_sessions()
-{
- var sessions = smbsrv_sessions();
- var i;
- var sys = sys_init();
- if (sessions == undefined) {
- println("No sessions open");
- return;
- }
- printf("User Client Connected at\n");
- printf("-------------------------------------------------------------------------------\n");
- for (i=0;i<sessions.length;i++) {
- var info = sessions[i];
- var fulluser = sprintf("%s/%s", info.account_name, info.domain_name);
- printf("%-30s %16s %s\n",
- fulluser, info.client_ip, sys.httptime(info.connect_time));
- }
- printf("\n");
-}
-
-/*
- show open tree connects
-*/
-function show_tcons()
-{
- var tcons = smbsrv_tcons();
- var sys = sys_init();
- if (tcons == undefined) {
- println("No tree connects");
- return;
- }
- printf("Share Client Connected at\n");
- printf("-------------------------------------------------------------------------------\n");
- for (i=0;i<tcons.length;i++) {
- var info = tcons[i];
- printf("%-30s %16s %s\n",
- info.share_name, info.client_ip, sys.httptime(info.connect_time));
- }
-}
-
-/*
- show nbtd information
-*/
-function show_nbt()
-{
- var stats = nbtd_statistics();
- if (stats == undefined) {
- println("nbt server not running");
- return;
- }
- var r;
- println("NBT server statistics:");
- for (r in stats) {
- print("\t" + r + ":\t" + stats[r] + "\n");
- }
- println("");
-}
-
-var lp = loadparm_init();
-
-printf("%s\n\n", lp.get("server string"));
-
-if (options['nbt'] != undefined) {
- show_nbt();
-} else {
- show_sessions();
- show_tcons();
-}
-
-return 0;
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# provide information on connected users and open files
+# Copyright ǒ Jelmer Vernooij 2008
+#
+# Based on the original in EJS:
+# Copyright Andrew Tridgell 2005
+# Released under the GNU GPL version 3 or later
+#
+
+import sys
+
+sys.path.insert(0, "bin/python")
+
+import optparse
+import samba.getopt as options
+import samba.irpc
+
+def show_sessions():
+ """show open sessions"""
+ sessions = smbsrv_sessions()
+ print "User Client Connected at"
+ print "-------------------------------------------------------------------------------"
+ for session in sessions:
+ fulluser = "%s/%s" % (session.account_name, session.domain_name)
+ print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time))
+ print ""
+
+def show_tcons():
+ """show open tree connects"""
+ tcons = smbsrv_tcons()
+ print "Share Client Connected at"
+ print "-------------------------------------------------------------------------------"
+ for tcon in tcons:
+ print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))
+
+
+def show_nbt():
+ """show nbtd information"""
+ stats = nbtd_statistics()
+ print "NBT server statistics:",
+ for r in stats:
+ print "\t" + r + ":\t" + stats[r] + "\n"
+ print ""
+
+parser = optparse.OptionParser("%s [options]" % sys.argv[0])
+sambaopts = options.SambaOptions(parser)
+parser.add_option_group(sambaopts)
+parser.add_option("--nbt", type="string", metavar="NBT",
+ help="show NetBIOS status")
+
+lp = sambaopts.get_loadparm()
+
+print "%s\n\n" % lp.get("server string")
+
+if opts.nbt:
+ show_nbt()
+else:
+ show_sessions()
+ show_tcons()
+
+return 0