This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
while (my $row = <>) { | |
chomp $row; | |
my $num_of_pipes = $row =~ tr/|//; | |
while (($num_of_pipes < 10) && ($num_of_pipes > 0)) { | |
my $next_line = <>; | |
$row .= $next_line; | |
$num_of_pipes = $row =~ tr/|//; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH=/usr/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/youruser/bin | |
DB=db | |
USER=usr | |
PASS=pw | |
PATHTO=/path/to/ | |
DIR=extract$(date +%Y%m%d) | |
#Declare an array of tables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE=`date "+%y-%m-%d_%H:%M:%S"` | |
TOPATH=/to/file/path | |
FROMPATH=/from/file/path | |
#Backup all shell script files in FROMPATH and put them in TOPATH | |
/bin/find $FROMPATH -type f -name '*.sh' -print0 | tar zcf $FILEPATH/scripts_backup_$DATE.tar.gz --null -T - | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Simple crontab backup | |
crontab -l > /crontab_stuff/crontab_backups_$(date +%Y%m%d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE [dbo].[IndexOptimize] @Databases = 'Envision, Envision_Web, Envision_US, Envision_US_Web', @UpdateStatistics = 'ALL', @LogToTable = 'Y'" -b | |
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE [dbo].[IndexOptimize] @Databases = 'Envision, Envision_Web, Envision_US, Envision_US_Web', @FragmentationLow = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', PageCountLevel = 0, @UpdateStatistics = 'ALL', @LogToTable = 'Y'" -b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Alter_Index information | |
SELECT DatabaseName, | |
SchemaName, | |
ObjectName, | |
CASE WHEN ObjectType = 'U' THEN 'USER_TABLE' WHEN ObjectType = 'V' THEN 'VIEW' END AS ObjectType, | |
IndexName, | |
CASE WHEN IndexType = 1 THEN 'CLUSTERED' WHEN IndexType = 2 THEN 'NONCLUSTERED' WHEN IndexType = 3 THEN 'XML' WHEN IndexType = 4 THEN 'SPATIAL' END AS IndexType, | |
PartitionNumber, | |
ExtendedInfo.value('(ExtendedInfo/PageCount)[1]','int') AS [PageCount], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Avg Fragmentation Percentages | |
DECLARE @DatabaseID int | |
SET @DatabaseID = DB_ID() | |
SELECT DB_NAME(@DatabaseID) AS DatabaseName, | |
schemas.[name] AS SchemaName, | |
objects.[name] AS ObjectName, | |
indexes.[name] AS IndexName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DB_NAME() AS DbName, name AS FileName, | |
size/128.0 AS CurrentSizeMB, | |
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0 AS FreeSpaceMB, | |
(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0)/1024 AS FreeSpaceGB | |
FROM sys.database_files; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
******************************************************************************************************************************** | |
Credits: @Jeremy | |
Posted: http://stackoverflow.com/questions/7048839/sql-server-query-to-find-all-permissions-access-for-all-users-in-a-database | |
******************************************************************************************************************************** | |
Security Audit Report | |
1) List all access provisioned to a sql user or windows user/group directly | |
2) List all access provisioned to a sql user or windows user/group through a database or application role | |
3) List all access provisioned to the public role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
A few notes: | |
- Remember the DB Master Key!! | |
- When creating certificates/keys be descriptive, as there may be many on your instance of SQL Server | |
**/ | |
IF (select Count(*) from sys.symmetric_keys where name like '%DatabaseMasterKey%') = 0 | |
BEGIN | |
CREATE master key Encryption by password = 'SomePassword'; |
OlderNewer