Wes Hardaker | 198aa3b | 2000-02-11 23:48:42 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 2 | |
| 3 | use DBI; |
| 4 | $hostname = 'localhost'; # Host that serves the mSQL Database |
| 5 | $dbname = 'snmp'; # mySQL Database name |
| 6 | $doit = 1; |
| 7 | |
| 8 | sub usage { |
Wes Hardaker | 4f3f21e | 2000-06-06 21:26:30 +0000 | [diff] [blame] | 9 | print "$0 [-H host] [-u user] [-p password] [-v] [-h] [-n] [-d] [-a] GROUP USER EMAILADDRESS\n"; |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 10 | exit 0; |
| 11 | } |
| 12 | |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 13 | while ($#ARGV > -1 && $ARGV[0] =~ /^-/) { |
| 14 | $_ = shift @ARGV; |
| 15 | usage if (/-h/); |
| 16 | $hostname = shift if (/-H/); |
Wes Hardaker | 9b389c6 | 2001-06-01 14:40:05 +0000 | [diff] [blame] | 17 | $sqluser = shift if (/-u/); |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 18 | $pass = shift if (/-p/); |
| 19 | $admin = 1 if (/-a/); |
| 20 | $verbose = 1 if (/-v/); |
| 21 | $delete = 1 if (/-d/); |
| 22 | $doit = 0 if (/-n/); |
| 23 | } |
| 24 | |
Wes Hardaker | 4f3f21e | 2000-06-06 21:26:30 +0000 | [diff] [blame] | 25 | ($group, $user, $email) = @ARGV; |
| 26 | |
| 27 | die "group $group is a reserved group name, you can't use it. Sorry." if ($group eq "default"); |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 28 | |
| 29 | die "no group specified" if (!defined($group)); |
| 30 | |
Wes Hardaker | 9b389c6 | 2001-06-01 14:40:05 +0000 | [diff] [blame] | 31 | ( $dbh = DBI->connect("DBI:mysql:database=$dbname;host=$hostname", $sqluser, $pass)) |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 32 | or die "\tConnect not ok: $DBI::errstr\n"; |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 33 | |
Wes Hardaker | 4f3f21e | 2000-06-06 21:26:30 +0000 | [diff] [blame] | 34 | DO("insert into usergroups(user, groupname, isadmin) values('$user', '$group', " . (($admin) ? "'Y'" : "'N'") . ")"); |
| 35 | if (defined($email)) { |
| 36 | DO("insert into oncall(user, groupname, email, days, hours) values('$user', '$group', '$email', '*', '*')"); |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 37 | } |
Wes Hardaker | 4f3f21e | 2000-06-06 21:26:30 +0000 | [diff] [blame] | 38 | |
Wes Hardaker | a932cb8 | 1999-04-12 21:32:43 +0000 | [diff] [blame] | 39 | $dbh->disconnect(); |
Wes Hardaker | 4f3f21e | 2000-06-06 21:26:30 +0000 | [diff] [blame] | 40 | |
| 41 | sub DO { |
| 42 | my $cmd = shift; |
| 43 | print $cmd,"\n" if ($verbose); |
| 44 | $dbh->do($cmd) if ($doit); |
| 45 | } |