diff options
author | CVS Import User <samba-bugs@samba.org> | 2004-04-04 09:21:52 +0000 |
---|---|---|
committer | CVS Import User <samba-bugs@samba.org> | 2004-04-04 09:21:52 +0000 |
commit | 9f765b7406282904ce56f2535dcd929a9aefc5ca (patch) | |
tree | dbdff78b624ac7c1afcb8851f395df3d99eb1f84 /examples/misc | |
parent | 111b4e05ab96eafc4212f38dc5977538907187c7 (diff) | |
download | samba-9f765b7406282904ce56f2535dcd929a9aefc5ca.tar.gz samba-9f765b7406282904ce56f2535dcd929a9aefc5ca.tar.xz samba-9f765b7406282904ce56f2535dcd929a9aefc5ca.zip |
r2: import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
metze
Diffstat (limited to 'examples/misc')
-rw-r--r-- | examples/misc/extra_smbstatus | 50 | ||||
-rwxr-xr-x | examples/misc/modify_samba_config.pl | 154 | ||||
-rw-r--r-- | examples/misc/swat.pl | 122 | ||||
-rw-r--r-- | examples/misc/wall.perl | 69 |
4 files changed, 395 insertions, 0 deletions
diff --git a/examples/misc/extra_smbstatus b/examples/misc/extra_smbstatus new file mode 100644 index 00000000000..7f77d07d00c --- /dev/null +++ b/examples/misc/extra_smbstatus @@ -0,0 +1,50 @@ +Here's something that Paul Blackman sent me that may be useful: + +------------------- +I created this script to do a few things that smbstatus doesn't at the +moment. Perhaps you might want to include these. Sorry I haven't +added things at source level, script was quick&easy. + +******* +#!/bin/csh +if ($1 == "-p") then + smbstatus -p |sort -u +else if ($1 == "-c") then + echo There are `smbstatus -p |sort -u |grep -n -v z |grep -c :` unique smbd processes running. + else if ($1 == "-l") then + echo `date '+ %d/%m/%y %H:%M:%S'` `smbstatus -p |sort -u |grep -n -v z |grep -c :` >>$2 +else if ($1 == "-cs") then + echo There are `smbstatus |awk '$1==share {n++;} END {print n}' share=$2` concurrent connections to share: $2 +else if ($1 == "-csl") then + echo `date '+ %d/%m/%y %H:%M:%S'` `smbstatus |awk '$1==share {n++;} END {print n}' share=$2` >>$3 +else + echo "'smbstat -c' ==> Count unique smbd processes." + echo "'smbstat -p' ==> List unique smbd processes." + echo "'smbstat -l logfile' ==> Append a log entry for the number of" + echo " concurrent and unique processes to logfile." + echo "'smbstat -cs sharename'" + echo " ==> Count processes connected to sharename (assumed unique)" + echo "'smbstat -csl sharename logfile'" + echo " ==> Append a log entry for the number of concurrent" + echo " processes connected to sharename (assumed unique)" +endif +****** + +Run this script from cron eg. + +0,5,10,15,20,25,30,35,40,50,55 * * * * /usr/local/samba/bin/smbstat -l /usr/local/samba/var/smbdcount.log + +and you get a good idea of usage over time. + +Cheers, +~^ MIME OK ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ + o | Paul Blackman ictinus@lake.canberra.edu.au + o | Co-operative Research ------------------------ + o _ | Centre For Freshwater Ecology. Ph. (Aus) 06 2012518 + -- (") o | University of Canberra, Australia. Fax. " 06 2015038 + \_|_-- |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | | "Spend a little love and get high" + _/ \_ | - Lenny Kravitz +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ SAMBA Web Pages: http://samba.org/samba/ ~~~~~~~~~~~~~~ + diff --git a/examples/misc/modify_samba_config.pl b/examples/misc/modify_samba_config.pl new file mode 100755 index 00000000000..ad958625d66 --- /dev/null +++ b/examples/misc/modify_samba_config.pl @@ -0,0 +1,154 @@ +#!/usr/bin/perl + +## +## Simple example of how to implement a '[add|delete] share command' for +## use with the Windows NT Server Manager. See smb.conf(5) for details +## on the '[add|delete] share command' +## +## Author : Gerald (Jerry) Carter <jerry@samba.org> +## + +use POSIX qw(tmpnam); + +## +## local variables +## +my $delete_mode = undef; +my $add_mode = undef; +my $tmp_file_name = undef; + + +## check for correct parameters +if ($#ARGV == 1) { + $delete_mode = 1; +} +elsif ($#ARGV == 3) { + $add_mode = 1; +} +else { + print "Usage: $0 configfile share [path] [comment]\n"; + exit -1; +} + +## first param is always the config file +open (CONFIGFILE, "$ARGV[0]") || die "Unable to open $ARGV[0] for reading!\n"; + +## FIXME!! Right now we throw away all comments in the file. +while (<CONFIGFILE>) { + + chomp($_); + + ## eat leading whitespace + $_ =~ s/^\s*//; + + ## eat trailing whitespace + $_ =~ s/\s*$//; + + + ## throw away comments + next if (($_ =~ /^#/) || ($_ =~ /^;/)); + + ## set the current section name for storing the hash + if ($_ =~ /^\[.*\]$/) { + + $_ = substr($_, 1, length($_)-2); + + if ( length($_) ) { + $section = $_; + } + else { + print "Bad Section Name - no closing ]\n"; + exit -1; + } + + next; + } + + ## check for a param = value + if ($_ =~ /=/) { + ($param, $value) = split (/=/, $_,2); + $param =~ s/./\l$&/g; + $param =~ s/\s+//g; + $value =~ s/^\s+//; + + $config{$section}{$param} = $value; + + next; + } + + ## should have a hash of hashes indexed by section name +} +close (CONFIGFILE); + +## +## We have the smb.conf in our hash of hashes now. +## Add or delete +## +if ($add_mode) { + $config{$ARGV[1]}{'path'} = $ARGV[2]; + $config{$ARGV[1]}{'comment'} = $ARGV[3]; +} +elsif ($delete_mode) { + delete $config{$ARGV[1]}; +} + +## +## Print the resulting configuration +## +#do { +# $tmp_file_name = tmpnam(); +# print "Using temporary file - $tmp_file_name\n"; +#} while (!sysopen(TMP, $tmp_file_name, O_RDWR|O_CREAT|O_EXCL)); +$tmp_file_name = tmpnam(); +open (TMP, ">$tmp_file_name") || die "Unable to open temporary file for writing!\n"; + +PrintConfigFile(TMP); + +## now overwrite the original config file +close (TMP); +system ("cp -pf $ARGV[0] $ARGV[0].bak"); +system ("cp -pf $tmp_file_name $ARGV[0]"); +unlink $tmp_file_name; + + +exit 0; + + + + + +####################################################################################### +## PrintConfigFile() +## +sub PrintConfigFile { + my ($output) = @_; + + ## print the file back out, beginning with the global section + print $output "#\n# Generated by $0\n#\n"; + + PrintSection ($output, 'global', $config{'global'}); + + foreach $section (keys %config) { + + if ("$section" ne "global") { + print $output "## Section - [$section]\n"; + PrintSection ($output, $section, $config{$section}); + } + } + + print $output "#\n# end of generated smb.conf\n#\n"; +} + +####################################################################################### +## PrintSection() +## +sub PrintSection { + my ($outfile, $name, $section) = @_; + + print $outfile "[$name]\n"; + foreach $param (keys %$section) { + print $outfile "\t$param".' 'x(25-length($param)). " = $$section{$param}\n"; + } + print $outfile "\n"; + +} diff --git a/examples/misc/swat.pl b/examples/misc/swat.pl new file mode 100644 index 00000000000..f6414b63497 --- /dev/null +++ b/examples/misc/swat.pl @@ -0,0 +1,122 @@ +#! /usr/bin/perl5 +## +## This is a simple script written by Herb Lewis @ SGI <herb@samba.org> +## for reporting which parameters are supported by loadparm.c but +## not by SWAT I just thought it looked fun and might be of interest to others +## --jerry@samba.org +## +## Here is a little info on the usage and output format so you don't have +## to dig through the code to understand what is printed. +## +## Useage: swat.pl [path_to_loadparm.c] +## +## The output consists of 4 columns of information +## Option Name, Global Page, Share Page, Printer Page +## The section separaters will also be printed (preceded by 16 *) to show +## which options are grouped in the various sections. +## +## If the option name is preceded by an * it means this is a deprecated option. +## If the option name is preceded by 5 spaces it means this is an alias for the +## previous option. +## +## Under the Global Page, Share Page, and Printer Page columns there will be +## one of 3 entries, BASIC, ADVANCED, or no. "BASIC" indicates this option will +## show in the Basic View of that page in SWAT. "ADVANCED" indicates this +## option will show in the Advanced View of that page in SWAT. "No" indicates +## that this option is not available on that page in SWAT. +## +## Under the Global Page column, if an entry begins with an * it indicates that +## this is actually specified in Samba as a "service parameter" not a "global +## parameter" but you can set a default value for this on the Global Page in +## SWAT. +## +## --herb@samba.org + +$lastone = "nothing"; + +if (@ARGV[0]) { + $filename = @ARGV[0]; +} else { + $filename = "/usr3/samba20/samba/source/param/loadparm.c"; +} + +open (INFILE,$filename) || die "unable to open $filename\n"; +while (not eof(INFILE)) +{ + $_ = <INFILE>; + last if ( /^static struct parm_struct parm_table/) ; +} +print "Option Name Global Page Share Page Printer Page\n"; +print "---------------------------------------------------------------------"; +while (not eof(INFILE)) +{ + $_ = <INFILE>; + last if (/};/); + @fields = split(/,/,$_); + next if not ($fields[0] =~ /^.*{"/); + $fields[0] =~ s/.*{"//; + $fields[0] =~ s/"//; + if ($fields[3] eq $lastone) { + print " $fields[0]\n"; + next; + } + $lastone = $fields[3]; + $fields[2] =~ s/^\s+//; + $fields[2] =~ s/\s+$//; + $fields[2] =~ s/}.*$//; + $fields[6] =~ s/^\s+//; + $fields[6] =~ s/\s+$//; + $fields[6] =~ s/}.*$//; + if ($fields[2] =~ /P_SEPARATOR/) { + print "\n****************$fields[0]\n"; + next; + } + else { + if ($fields[6] =~ /FLAG_DEPRECATED/) { + print "*$fields[0]".' 'x(31-length($fields[0])); + } + else { + print "$fields[0]".' 'x(32-length($fields[0])); + } + } + if (($fields[2] =~ /P_GLOBAL/) || ($fields[6] =~ /FLAG_GLOBAL/)) { + if ($fields[6] =~ /FLAG_GLOBAL/) { + print "*"; + } + else { + print " "; + } + if ($fields[6] =~ /FLAG_BASIC/) { + print "BASIC "; + } + else { + print "ADVANCED "; + } + } + else { + print " no "; + } + if ($fields[6] =~ /FLAG_SHARE/) { + if ($fields[6] =~ /FLAG_BASIC/) { + print "BASIC "; + } + else { + print "ADVANCED "; + } + } + else { + print "no "; + } + if ($fields[6] =~ /FLAG_PRINT/) { + if ($fields[6] =~ /FLAG_BASIC/) { + print "BASIC"; + } + else { + print "ADVANCED"; + } + } + else { + print "no"; + } + print "\n"; +} diff --git a/examples/misc/wall.perl b/examples/misc/wall.perl new file mode 100644 index 00000000000..9303658ce14 --- /dev/null +++ b/examples/misc/wall.perl @@ -0,0 +1,69 @@ +#!/usr/local/bin/perl +# +#@(#) smb-wall.pl Description: +#@(#) A perl script which allows you to announce whatever you choose to +#@(#) every PC client currently connected to a Samba Server... +#@(#) ...using "smbclient -M" message to winpopup service. +#@(#) Default usage is to message every connected PC. +#@(#) Alternate usage is to message every pc on the argument list. +#@(#) Hacked up by Keith Farrar <farrar@parc.xerox.com> +# +# Cleanup and corrections by +# Michal Jaegermann <michal@ellpspace.math.ualberta.ca> +# Message to send can be now also fed (quietly) from stdin; a pipe will do. +#============================================================================= + +$smbstatus = "/usr/local/bin/smbstatus"; +$smbshout = "/usr/local/bin/smbclient -M"; + +if (@ARGV) { + @clients = @ARGV; + undef @ARGV; +} +else { # no clients specified explicitly + open(PCLIST, "$smbstatus |") || die "$smbstatus failed!.\n$!\n"; + while(<PCLIST>) { + last if /^Locked files:/; + split(' ', $_, 6); + # do not accept this line if less then six fields + next unless $_[5]; + # if you have A LOT of clients you may speed things up by + # checking pid - no need to look further if this pid was already + # seen; left as an exercise :-) + $client = $_[4]; + next unless $client =~ /^\w+\./; # expect 'dot' in a client name + next if grep($_ eq $client, @clients); # we want this name once + push(@clients, $client); + } + close(PCLIST); +} + +if (-t) { + print <<'EOT'; + +Enter message for Samba clients of this host +(terminated with single '.' or end of file): +EOT + + while (<>) { + last if /^\.$/; + push(@message, $_); + } +} +else { # keep quiet and read message from stdin + @message = <>; +} + +foreach(@clients) { +## print "To $_:\n"; + if (open(SENDMSG,"|$smbshout $_")) { + print SENDMSG @message; + close(SENDMSG); + } + else { + warn "Cannot notify $_ with $smbshout:\n$!\n"; + } +} + +exit 0; + |