NathanFriend.co.uk

Developers notebook

Scan a network for MS SQL servers

nmap -p T:1433 -sV 192.168.1.2-254 -oG tcp_scan_results.txt

Source: https://www.mssqltips.com/sqlservertip/2753/using-nmap-to-scan-for-sql-servers-on-a-network/

Start MySQL on Yosemite

sudo /usr/local/mysql/support-files/mysql.server start

Orignal source: http://osxdaily.com/2014/11/26/start-stop-mysql-commands-mac-os-x/

Monitor MySQL restore progress with pv

pv {source_database.sql} | mysql -u{user} -p {destination_database}

source https://major.io/2010/11/24/monitor-mysql-restore-progress-with-pv/

Duplicate a directory structure.

From the root of structure you want to duplicate run find . -maxdepth 2 -type d | sed 's/$/"/' | sed 's/^/mkdir "/' > create.sh

-maxdepth sets the recursion level.
-type d identifies only directories.
sed commands wrap the output in mkdir “{Path}”

Output is redirected to a file.

MS Access Sum a date time field

Example data

id TimeElapsed User
1 00:01:44 Bob
2 00:01:46 Bob

To sum a date time field first convert the field data to double with an expression using the CDbl Function.

exp1: CDbl([TimeElapsed])

Set the total type to Sum.

Then create another expression to convert the data from the first expression back to a date time field using the CVDate function.

exp2: CVDate([exp1])

Set the total value to Expression.

TimeElapsed User
00:03:30 Bob

UNIX timestamp and Active Directory timestamp for given date and time

<php
/** Returns UNIX timestamp and Active Directory timestamp for given date and time */

date_default_timezone_set('Europe/London');

//Format dd-mm-yyyy
$dateFromForm = '24-05-2020';

//Format hh:mm:ss
$timeFromForm = "00:00:00";

$CLI = 1;
if ($CLI = 0) { $LF = "<br>";} else {$LF = "\r\n";}
$dateWithTime = $dateFromForm." ".$timeFromForm;

function convertDateToUnix($input) {
$format = 'd-m-Y H:i:s';
$date = DateTime::createFromFormat($format, $input);
$UNIXTimestamp = $date->getTimestamp();
return $UNIXTimestamp;
}

function convertUnixtoWin($input) {
return ($input+11644473600)*10000000;
}

$UNIX=convertDateToUnix($dateWithTime);
echo "*** Welcome to the Timestamp converter ***".$LF;
echo $LF."You entered: ".$dateWithTime.$LF;
echo $LF."UNIX Timestamp is ".$UNIX.$LF;
echo $LF."Windows Timestamp is ".convertUnixtoWin($UNIX).$LF;
echo $LF."**************************************".$LF;

Amazon ec2 CLI – Return instance public DNS by tag

aws ec2 describe-instances –output=json –filter Name=tag:{TAG NAME},Values=”{TAG VALUE}” –query “Reservations[].Instances[].PublicDnsName”

For example if you have some ec2 instances with a tag key “Name” and the value “Webserver Auto Scaling Group”

aws ec2 describe-instances –output=json –filter Name=tag:Name,Values=”Webserver Auto Scaling Group” –query “Reservations[].Instances[].PublicDnsName”

Find and replace a line with sed

sed -i “/;Thing to find/c\Thing to replace it with” /path/to/file

sed -i “/;date.timezone =/c\date.timezone = Europe/London” /etc/php.ini

Load data in to Maria DB from csv file

Place your import data file inside the database data directory e.g /var/lib/mysql/{database name}

Give the mysql user permission.  chown mysql:mysql {data.csv}

mysql -uroot -p –local-infile=1 {database name}

Load the data:

LOAD DATA INFILE ‘{data.csv}’
INTO TABLE  {table name}
FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\r\n’

If your data has a field headings row, this can be omitted from the import with.
IGNORE 1 LINES;

NTLM error on openSUSE 13.2

When setting up NTLM on openSUSE I was getting a 500 server error from Apache.

In the error log: ntlm_auth reports Broken Helper: BH NT_STATUS_ACCESS_DENIED NT_STATUS_ACCESS_DENIED

Solved with setfacl -m u:wwwrun:rx /var/lib/samba/winbindd_privileged

« Older posts

© 2016 NathanFriend.co.uk

Theme by Anders NorenUp ↑