#!/usr/bin/perl use warnings; use strict; use Getopt::Long; my $path = "/usr/local/samba/sbin"; my $run = 9; my $stop = 9 ; my $status = 9; GetOptions('run' => \$run, 'stop' => \$stop, 'status' => \$status); #print "run: $run, stop: $stop\n"; if($status == 1) { print "Status...\n"; &checkStatus(1); } elsif ($run == 9 && $stop == 9 && $status == 9) { print "Usage: ./runSamba --run [stop|status]\n"; } elsif($stop == 9 && $run == 1) { print "Starting Samba!\n"; &runSamba($run); } elsif($run == 9 && $stop == 1) { print "Stopping Samba\n"; &runSamba(0); } sub runSamba { my $choice = shift; if($choice == 1) { system("$path/nmbd -D"); system("$path/smbd -D"); &checkStatus($choice); } else { foreach(`ps auxwww`) { if(/(nmbd|smbd)/) { print; if(/^\w+\s+(\d+)\s+.*$/) { system("kill -9 $1"); #print "process? $1\n"; } } } &checkStatus($choice); } } sub checkStatus { my $choice = shift; foreach(`ps auxwww`) { if(/^(USER|PID|\%CPU|\%MEM|START|TIME|COMMAND)/) { print; } if(/(nmbd|smbd)/) { print; } } }