Gheek.net

February 20, 2008

Creating a new user and permissions in mysql

Filed under: database, mysql — Tags: , — lancevermilion @ 1:39 am

Typically in MySQL you need to create a database for an application to use and a user which that application will use to access that database. Here is how I normally do this.

Create the database using mysqladmin

sudo mysqladmin -u root -p create

Create a user with basic permissions
First we need to select the mysql database so we can create a user.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Now we need to create the database_user with permissions.

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database_name.* TO 'database_user'@'localhost' IDENTIFIED BY 'database_user_password';
Query OK, 0 rows affected (0.02 sec)

Advertisement

February 15, 2008

End of the World

Filed under: swf — Tags: — lancevermilion @ 3:57 pm

[kml_flashembed movie=”http://www.gheek.net/oldweb/swf/EOW.swf” height=”150″ width=”300″ /]

Solarwinds_report_sh

Filed under: shell scripts, solarwinds — Tags: , — lancevermilion @ 3:37 pm

This is used with the following files to create the Solarwinds report.
Calls Solarwinds_report.pl which uses Solarwinds_sample_wanstatusinput

#!/bin/sh
#
# Call cat /usr/local/bin/statusinput.txt | /usr/bin/perl /usr/local/bin/solarwinds_report.pl
#
/bin/cat /srv/www/htdocs/reports/inputfiles/Solarwinds_sample_wanstatusinput.txt | /usr/bin/perl /usr/local/bin/solarewinds_report.pl > /srv/www/htdocs/reports/WWOSR-`date +%m-%d-%Y`.html

echo "Please go to http://SOME_SOLARWINDS_SERVER_URL to login.
Then you can go to the URL below to view the report.
The report will only show graphs if you are logged into http://SOME_SOLARWINDS_SERVER_URL.

https://SOME_SOLARWINDS_SERVER_URL/reports/BWNOSR-`date +%m-%d-%Y`.html

-Status Report Generator" | mailx -r "SOME_FROM_USER_AT_SOME_DOMAIN" -s "Weekly WAN Operations Report" SOME_TO_USER_AT_SOME_DOMAIN

Solarwinds_report_pl

Filed under: perl, solarwinds — Tags: , — lancevermilion @ 3:32 pm

This creates a report form information that solarwinds has. Perfect for management that needs bits of information on what is going on. Unfortunately at the time I wrote this Solarwinds didn’t support anything like this.

Make sure you use the sample input file from “Solarwinds_sample_wanstatusinput“.

This script is called by Solarwinds_report.sh

Solarwinds_report.sh
#!/usr/bin/perl -w

#
# Use the DateTime perl module
#
use DateTime;
#
# Set the timezone to Phoenix time and create an object that hold the current time
#
my $dt = DateTime->now(time_zone => 'America/Phoenix' );

#
# Subtract 1 day from today (as this is suppose to run only on mondays)
#
$dt->subtract( days => 1 );
my $YESTERDAY = $dt->mdy('/');

#
# Subtract 6 day from sunday to represent last monday
#
$dt->subtract( days => 6 );
my $LASTWEEKYESTERDAY = $dt->mdy('/');

#
# print the html required to document everything.
#
print'


Weekely Network Operations Status Report

     P.breakhere {page-break-before: always}



Weekly Network Operations Status Report

' . "\n"; # # while we read everything into this script preform a variety of tasks # while () { # # Match lines that start with Circuit: follow by a space and anything till the end of the line. # print '

'. $2 . '

' . "\n" if ( /^(Circuit:)\s(.*$)/ ); # # Match lines that start with Provider follow by anything # until Type: followed a space and anything till the end of the line. # print '' . $1 . ' ' . $2 . "
\n" if ( /^(Provider.*Type:)\s(.*$)/ ); # # Match lines that start with Speed: follow by a space and anything till the end of the line. # print '' . $1 . ' ' . $2 . "
\n" if ( /^(Speed:)\s(.*$)/ ); # # Match lines that start with Primary follow by anything # until : followed a space and anything till the end of the line. # print '' . $1 . ' ' . $2 . "
\n" if ( /^(Primary.*:)\s(.*$)/ ); # # Match lines that start with Summary: follow by a space and anything till the end of the line. # print '' . $1 . ' ' . "
\n$2\n
\n" if ( /^(Summary:)\s(.*$)/ ); # # Match lines that start with N: follow by a space and anything till the end of the line. # $NODENUM = $1 if ( /^N:\s(\d+).*$/ ); # # Match lines that start with I: follow by a space and anything till the end of the line. # $INTERFACENUM = $1 if ( /^I:\s(\d+).*$/ ); if ( /^(I:)\s(\d+)/ ) { print "\n
\n"; print '' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print '
Utilization statistics
From: ' . "$LASTWEEKYESTERDAY" . ' To: ' . "$YESTERDAY" . '
Response Time Statistics
From: ' . "$LASTWEEKYESTERDAY" . ' To: ' . "$YESTERDAY" . '
Utilization GraphResponse Time Graph
' . "\n"; print '
' . "\n"; print '
' . "\n"; print 'Issues:
' . "\n"; print '' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print ' ' . "\n"; print '
N/A
' . "\n"; print '

' . "\n"; } #next if ( /^(Summary:)\s(.*$)/ ); } print ' ' . "\n";

Solarwinds_sample_wanstatusinput

Filed under: solarwinds — Tags: — lancevermilion @ 3:32 pm

This is a sample input that is used with Solarwinds_report_pl


Circuit: Circuit Description
Provider / Type: Vendor / Circuit Type
Speed: xxx kbps/mbps/gbps/etc
Primary Service: What is this link used for? Maybe link to Chase Bank
Summary: Short description of what this ciruit is used for and what kind of traffic goes over this link
N:
I:

sampleswitchmap_ThisSite_pm.txt

Filed under: perl, switchmap — Tags: , — lancevermilion @ 3:26 pm

This is a sample of “ThisSite.pm” for Switchmap when using my other add-ons.

package ThisSite;

#
# This package defines site-specific constants used by the SwitchMap
# programs.
#

# Set $GetSwitchListFromHpOpenView to 1 (true) if you have HP OpenView
# Network Node Manager (NNM) running on a machine at your site, and
# you want SwitchMap to get the list of your switches from OpenView.
# This is a good thing to do if you can, because as you add/remove
# switches from your network, SwitchMap automatically adjusts.  If you
# leave $GetSwitchListFromHpOpenView set to 0 (false), SwitchMap will
# use the static @LocalSwitches array defined below.
$GetSwitchListFromHpOpenView = 0;

# Set $GetMacIpAddrFromHpOpenView to 1 (true) if you have HP OpenView
# Network Node Manager (NNM) running on a machine at your site, and
# you want SwitchMap to get the MAC-to-IP mapping tables from
# OpenView.  This is a good thing to do if you have OpenView and you
# have OpenView configured to manage all your hosts on all your
# networks.  Otherwise, leave $GetMacIpAddrFromHpOpenView set to 0
# (false) and SwitchMap will get the data from the MacList file (see
# the README file for an explanation of the MacList file)
$GetMacIpAddrFromHpOpenView = 0;

# Set $GetSnmpCommunitiesFromHpOpenView to 1 (true) if you have HP
# OpenView Network Node Manager (NNM) running on a machine at your
# site, and you want SwitchMap to get SNMP community strings from
# OpenView.  If you have OpenView and you have configured OpenView
# with SNMP community strings, setting this variable to true lets you
# avoid maintaining 2 lists of SNMP community strings.  Otherwise,
# leave $GetSnmpCommunitiesFromHpOpenView set to 0 (false) and see the
# comment that describes the $Community variable below.
$GetSnmpCommunitiesFromHpOpenView = 0;

# If you have HP OpenView Network Node Manager at this site (any of
# the previous 3 variables are set to true), then this program will
# get information from NNM.  To do so, this program needs to know the
# DNS name of the machine that is running HP OpenView NNM.  If the
# SwitchMap programs are running on the same machine as HP OpenView
# NNM, set $OpenViewHost to 'localhost'.  If HP Openview NNM is
# running on another machine, put the name here, and this program will
# ssh to the machine.  For this to work, you have to have ssh access
# to the machine defined by $OpenViewHost such that the user that runs
# the SwitchMap scripts is able to ssh to $OpenViewHost without
# supplying a password.  If the previous 3 variables are set to 0
# above, then it doesn't matter what value $OpenViewHost has.
$OpenViewHost = 'nnm.your.domain';

# If you have HP OpenView Network Node Manager at this site and NNM is
# running on another host, then this is the ssh key to use to get the
# switch lists and MAC data and the SNMP community strings file.
# SwitchMap will use this string as the argument of the "-i" option
# when SwitchMap does ssh or scp commands to get data from the remote
# host.
$SshKeyOption = '';

# If you do not have HP OpenView Network Node Manager at this site
# ($Has_HP_OpenView = 0 above), then you'll need to run GetArp.pl
# periodically to get IP and MAC data from your CSSes/routers. The
# @routers array list the devices that the GetArp program will query.
@routers = ('router1' , 'router2');

# File protection to be applied to all output files.  This value is
# used in "chmod" calls, and is usually specified in octal (in Perl,
# scalar integers specified with a leading zero are octal, not
# decimal).  The default given here is fine for most sites.
$FileProtectionModes = 0644;   # 0644 = "-rw-r-r--"

# @LocalSwitches provides a static list of switches when you have
# $GetSwitchListFromHpOpenView set to 0.  If you have
# $GetSwitchListFromHpOpenView set to 1, SwitchMap ignores the
# contents of @LocalSwitches.  This list is used by ScanSwitch.pl
# and SwitchMap.pl.
@LocalSwitches = ('switch1' , 'switch2');

@LocalSwitchesFilter = ('switch1,Gi5/2:Gi5/1:Gi1/13:Gi1/36:Gi1/35:Gi1/14:Gi1/47:Gi1/48:Gi1/1:Gi1/2:Gi4/5:Gi4/14:Gi4/8:Gi4/6:Gi3/10:Gi3/8:Gi4/11:Gi4/13:Fa9/18:Fa9/17:Gi3/16:Gi4/10:Gi4/9:Gi4/15:Gi3/12:Gi4/4:Gi3/13:Gi3/15:Gi3/9:Gi4/16',
                  'switch2,Gi5/2:Gi5/1:Gi1/14:Gi1/13:Gi1/35:Gi1/36:Gi1/2:Gi1/1:Gi1/47:Gi1/48:Gi3/3:Gi4/8:Gi4/6:Gi4/3:Gi3/8:Gi3/7:Gi3/6:Gi3/4:Gi3/15:Gi4/10:Gi4/9:Gi4/15:Gi3/12:Gi4/4:Gi3/13:Gi3/16:Gi3/9:Gi4/16'
                  );

# If you have HP OpenView and you've set $GetSwitchListFromHpOpenView
# to 1, it may match some switches that you don't want to appear in
# the port lists.  For example, at my site we have a network connection
# to a Catalyst that we monitor with HP OpenView even though we
# don't have administrative control of the switch.  So when SwitchMap
# finds all the Catlaysts known to HP OpenView, it finds the switch
# along with all our other switches.  By putting that switch in the
# @SkipTheseSwitches list, we can make SwitchMap skip that switch.
@SkipTheseSwitches = ('ithaka-router');

# If you use the same community string for all your switches, leave
# $CmstrFile as an empty string and set the $Community variable found
# below.  If you use different community strings on different
# switches, set $CmstrFile to the full pathname of a file that defines
# the strings.  The format of the file is intentionally identical to
# that of the netmon.cmstr file used by HP OpenView NNM, so that sites
# that have NNM can simply use their existing NNM file.  The file must
# contain one community string per line, in double quotes.  Duplicates
# are ignored, as are lines that start with '#'.  On each line of the
# file, everything after the second double-quote character is ignored.
# If you have HP OpenView, set $CmstrFile to the full path name of the
# netmon.cmstr file, including the 'netmon.cmstr' at the end, and this
# program will try to open the file on the HP OpenView machine defined
# by $OpenViewHost above.  Specify the real full path name, without
# using any environment variables like OV_CONF.  If you don't have HP
# OpenView, set $CmstrFile to the full pathname of a file.  For each
# switch, this program will try the community strings defined in the
# file, one after the other.
$CmstrFile = '';

# If you use the same SNMP community string in all your switches, set
# $Community to that value.  If your switches have different community
# strings, set the $CmstrFile variable above.  When that variable is
# set to a non-empty value, SwitchMap ignores the value of the
# $Community variable.  Note: the SwitchMap programs do only "get"
# SNMP requests - no SNMP "set" requests are done.
$Community = 'SOME_COMMUNITY';

# Your DNS domain.  A typical switch in our network is "abc.ucar.edu",
# so we set this to '.ucar.edu'.
$DnsDomain = 'abc.com';

# The $WorkingDirectory variable is the full path to the working
# directory (where the code is).  This is where the program finds some
# Perl modules.
$WorkingDirectory = '.';

# The $CgiDir variable is the directory that the FindOffice.pl
# program was copied to when the SwitchMap program was installed.
# Specify the directory relative to the root directory configured into
# the web server.  The web server has to be configured to allow
# scripts that live in this directory to be executed.  On my Linux
# system running an Apache web server, the CGI directory is
# /usr/web/nets/cgi/, so I edited the /etc/apache file and added a
# line that says
#
#   ScriptAlias /nets/cgi /usr/web/nets/cgi/
#
$CgiDir = '/srv/www/cgi-bin';

# Set $HasFinder to 1 if the "finder.py" CGI program is installed on
# your web server.  Setting it to 1 will cause SwitchMap to include a
# link to the page when it creates the portlists index page.  The
# "finder.py" program accepts an IP or MAC address from the user and
# dynamically walks through network devices to find a given address.
# It then displays the switch information related to the address
# (switch, port, port label).  The program is not portable to sites
# other than NCAR, so you're not likely to have it, so you should
# probably leave $HasFinder set to 0.
$HasFinder = 0;

# Set HasConfRooms to 1 if you have a static webpage named
# conference-rooms.html that describes your site's conference rooms.
# Setting it to 1 will cause SwitchMap to include a link to the page
# when it creates the portlists index page.  NCAR has such a page.
# You're not likely to have it, so you should probably leave
# $HasConfRooms set to 0.
$HasConfRooms = 0;

# The $WebPageTrailer variable contains a site-specific trailer on
# each web page.
$WebPageTrailer = <<wpt;
Address comments or questions about this Web page to
SOMEADMIN\@$DnsDomain.
WPT # The $ExtraHelpText string contains extra site-specific text that is # written to the help file. The help file explains how the search # function is used. At my site, I initialize this variable with text # that explains how we use the "name" fields in Cisco switches at our # site. You can safely leave this empty. $ExtraHelpText = ''; # The number of days past which a port is considered "unused". $UnusedAfter = 60; # days # The campus name $Campus = "HQ"; # # EVERYTHING BELOW THIS IS USED FOR ARCHIVESETUP.PL and jimmenu # # If you want to archive the output that switchmap generates then # set this to 1, otherwise set it to 0. $Archive = 1; # If you decide to archive the output that switchmap generates then # choose how many archives you want. By default archive is expected # to run once every hour to keep a very accurate list of hosts. # The default number is 23 because using the 24 hour clock you start # counting at 00 hundred hours and end at 23 hundred hours. $ArchiveQuantity = 23; # Point this to your cgi-bin directory that is # used for switchmap we want to know the absolute # location of the cgi directory $Webaccess_cgifile = '../../../cgi-bin/FindOfficeHQ.pl'; $Absoluteloc_cgifile = "$CgiDir/FindOfficeHQ.pl"; # Point this to your switchmap web directory # directory. (ex. /var/www/html/switchmap) $Webdir = '/srv/www/htdocs/switchmap/HQ'; # # Stuff below here is strictly for Jimmenu # # If you want to see a detailed menu for each archive that is created # then set this to 1. The Desktop/Server Distribution has the detailed # menu enabled. To enable the detailed menu for archives set this to 1. # # NOTE: When setting this to 1, if you do 24 hours worth of archives, # the menu will take about 2-3 seconds per page to load since it # is loaded each time the page is changed. # # Sample menu in ascii below # # Switchmap | HQ - Phoenix, AZ # |_ Desktop/Server Distribution # |_ Archive # |_12 AM # |_ Search the portlist # |_ Switches # |_ Modules # |_ Ports # | |_ Unused Ports # | |_ Emergency Ports # | |_ Gigabit Ports per Vlan # |_ Vlans # |_ Statistics # # |_12 AM # $ArchiveMenuDetail = 1; # This is pointing to the location of which # jimmenu is installed. If your switchmap # web directory is "/var/www/html/switchmap", # then define below as /switchmap. $Webaccess_webdir_root = '/switchmap'; $Webaccess_webdir = '/switchmap/HQ'; 1;

Red Team Green Team

Filed under: Uncategorized — lancevermilion @ 3:24 pm

If you work for a large company it will remind you of exactly how they do things. LOL. Worth taking a moment to view this one.

PHP Cheat Sheet

Filed under: cheatsheets, php — Tags: , , , — lancevermilion @ 3:07 pm

php_cheat_sheet

MySQL Cheat Sheet

Filed under: cheatsheets — Tags: , , — lancevermilion @ 3:06 pm

mysql_cheat_sheet

Javascript Cheat Sheet

Filed under: cheatsheets, javascript — Tags: , , , — lancevermilion @ 3:06 pm

javascript_cheat_sheet

Older Posts »

Create a free website or blog at WordPress.com.