AD Powershell

After running Windows Server 2016 recently with a DC, I’ve started using Powershell to perform AD functions. Here are a few basics.

New-ADUser cmdlet to create a new user:

 New-ADUser -Name John.Smith 

The above would only create the username, create a new user with more associations:

 New-ADUser -Name John Smith -GivenName John -Surname Smith -Path "OU=Staff,DC=Company,DC=Com" 

Add the password for above account:

 $password = "Strong Password" | ConvertTo-SecureString -AsPlainText -Force
New-ADUser -Name John.Smith -GivenName John -Surname Smith -Path "OU=Staff,DC=Company,DC=Com" 

Bulk Import Users with New-ADUser:

$Import =Import-CSV "c:\utils\aduserimport.csv"
$OU = "OU=staff,DC=ausinfotech,DC=local"
Foreach ($user in $Import)
{
$password = $user.Password | ConvertTo-SecureString -AsPlainText -Force
New-ADUser -Name $user.Name -GivenName $user.FirstName -Surname $user.LastName -Path $OU -AccountPassword $Password -ChangePasswordAtLogon $True -Enabled $True
}

The above script imports the CSV file, sets the standard OU and calls each data record (line of your CSV), writes the password and creates the user account. We are using a “Foreach”-loop, which loads each user record with its parameters from the CSV file.

See here for more info:
http://activedirectoryfaq.com/2016/04/ad-powershell-basics-new-aduser

rclone

Rclone is a command line program to sync files and directories to and from:

  • Google Drive
  • Amazon S3
  • Openstack Swift / Rackspace cloud files / Memset Memstore
  • Dropbox
  • Google Cloud Storage
  • Amazon Drive
  • Microsoft OneDrive
  • Hubic
  • Backblaze B2
  • Yandex Disk
  • SFTP
  • The local filesystem

Features:

  • MD5/SHA1 hashes checked at all times for file integrity
  • Timestamps preserved on files
  • Partial syncs supported on a whole file basis
  • Copy mode to just copy new/changed files
  • Sync (one way) mode to make a directory identical
  • Check mode to check for file hash equality
  • Can sync to and from network, eg two different cloud accounts
  • Optional encryption (Crypt)
  • Optional FUSE mount (rclone mount)

More info at https://rclone.org/

cmder

Cmder http://cmder.net/ is a software package created out of pure frustration over the absence of nice console emulators on Windows. It is based on amazing software, and spiced up with the Monokai color scheme and a custom prompt layout, looking sexy from the start.

Highly recommend installing the full version as it provides all the Linux utils including ls for a dir in Windows!

netdata real-time performance monitoring for Linux

Netdata is a real-time performance monitoring solution.

Unlike other solutions that are only capable of presenting statistics of past performance, netdata is designed to be perfect for real-time performance troubleshooting.

Netdata is a linux daemon you run, which collects data in realtime (per second) and presents a web site to view and analyze them. The presentation is also real-time and full of interactive charts that precisely render all collected values.

Netdata has been designed to be installed on every system, without disrupting the applications running on it:

  • It will just use some spare CPU cycles (check Performance).
  • It will use the memory you want it have (check Memory Requirements).
  • Once started and while running, it does not use any disk I/O, apart its logging (check Log Files). Of course it saves its DB to disk when it exits and loads it back when it starts.
  • You can use it to monitor all your systems and applications. It will run on Linux PCs, servers or embedded devices.

Out of the box, it comes with plugins that collect key system metrics and metrics of popular applications.

Available here: https://github.com/firehol/netdata

Midnight Commander file size format

When dealing with large files in MC, I have difficulties counting the digits to get the order of magnitude of the file size (hundreds of MB, or tens of GB, etc.). Sometimes, I use the trick to press insert key, which highlights the file and shows the file size in a nicely formatted way (i.e. 123,456,789), which makes it a thousand times more readable.

You can modify the configuration:

You can adjust the displayed digits with the column size option, see the “Listing mode” section in the manual. The file to edit is ~/.config/mc/panels.ini.

To list the file sizes as K, M or G use a narrow size column using the user_format key:

[New Left Panel]
user_format=half type name mark size:4 space mtime

Cherrytree Note Taking / Organiser

Cherrytree is a hierarchical note taking application, featuring rich text and syntax highlighting, storing data in a single xml or sqlite file.

Features:

  • rich text (foreground color, background color, bold, italic, underline, strikethrough, small, h1, h2, h3, subscript, superscript, monospace)
  • syntax highlighting supporting several programming languages
  • images handling: insertion in the text, edit (resize/rotate), save as png file
  • embedded files handling: insertion in the text, save to disk
  • multi-level lists handling (bulleted, numbered, to-do and switch between them, multiline with shift+enter)
  • simple tables handling (cells with plain text), cut/copy/paste row, import/export as csv file
  • codeboxes handling: boxes of plain text (optionally with syntax highlighting) into rich text, import/export as text file
  • alignment of text, images, tables and codeboxes (left/center/right/fill)
    hyperlinks associated to text and images (links to webpages, links to nodes/nodes + anchors, links to files, links to folders)
  • spell check (using pygtkspellcheck and pyenchant)
  • intra application copy/paste: supported single images, single codeboxes, single tables and a compound selection of rich text, images, codeboxes and tables
  • cross application copy/paste (tested with libreoffice and gmail): supported single images, single codeboxes, single tables and a compound selection of rich text, images, codeboxes and tables
  • copying a list of files from the file manager and pasting in cherrytree will create a list of links to files, images are recognized and inserted in the text
  • print & save as pdf file of a selection / node / node and subnodes / the whole tree
  • export to html of a selection / node / node and subnodes / the whole tree
  • export to plain text of a selection / node / node and subnodes / the whole tree
  • toc generation for a node / node and subnodes / the whole tree, based on headers h1, h2 and h3
  • find a node, find in selected node, find in selected node and subnodes, find in all nodes
  • replace in nodes names, replace in selected node, replace in selected node and subnodes, replace in all nodes
  • iteration of the latest find, iteration of the latest replace, iteration of the latest applied text formatting
  • import from html file, import from folder of html files
  • import from plain text file, import from folder of plain text files
  • import from basket, cherrytree, epim html, gnote, keepnote, keynote, knowit, mempad, notecase, rednotebook, tomboy, treepad lite, tuxcards, zim
  • export to cherrytree file of a selection / node / node and subnodes / the whole tree
  • password protection (using http://www.7-zip.org/) – NOTE: while a cherrytree password protected document is opened, an unprotected copy is extracted to a temporary folder of the filesystem; this copy is removed when you close cherrytree
  • tree nodes drag and drop

Download and details:
http://www.giuspen.com/cherrytree/

400+ Free Resources for DevOps & Sysadmins

In 2014 Google indexed 200 Terabytes of data (1 T of data is equal to 1024 GB, to give you some perspective). And, it’s estimated that Google’s 200 TB is just .004% of the entire internet. Basically the internet is a big place with unlimited information.

So in an effort to decrease searching and increase developing, Morpheus Data published this massive list of free resources for DevOps engineers and System Admins, or really anyone wanting to build something useful out of the internet.

All these resources are free, or offer some kind of free/trial tier. You can use any/all of these tools personally, as a company, or even suggest improvements (in the comments). It’s up to you.

If you find this list useful, please share it with your DevOps/SysAdmin friends on your favorite social network, or visit Morpheus Data to learn how you can 4x your application deployment.

http://www.nextbigwhat.com/devops-sysadmin-tools-resources-297/?_utm_source=1-2-2

MySQL—Some Handy Know-How

From an article on Linux Journal http://www.linuxjournal.com/content/mysql%E2%80%94some-handy-know-how below are the commands to get you quickly up and running with MySQL. But the Linux Journal Site will provide many more examples and sample data etc.

Create database phplogcon and assign rsyslog access rights:

mysql -u root -p
create database phplogcon;
GRANT ALL ON phplogcon.* TO [email protected] IDENTIFIED BY "password";

Check database and connection with rsyslog works:

mysql -u rsyslog -p
connect phplogcon;
show tables;
quit

Create User:

CREATE USER 'keith'@'localhost' IDENTIFIED BY 'mypass';

Some basic / useful commands are as follows :

- connect to MySQL 
 
   mysql -uUsername -pPassword 
 
- connect to MySQL , directly to a database 
   
   mysql -uUsername -pPassword DbName 
 
- upload a MySQL schema into my Database 
 
   mysql -uUsername -pPassword DbName < schema.sql 
 
- dump a DB (copy DB for backup) 
 
   mysql -uUsername -pPassword DbName > contents-of-db.sql 
 
While connected to MySQL : 
 
- display all databases 
 
   show databases; 
 
- connect to a Database 
 
   use DbName; 
 
- view tables of a Database (must be connected to the Database) 
 
   show tables;

Create MySQL User for Backups e.g. sqlbu

CREATE USER 'sqlbu'@'localhost' IDENTIFIED BY  '***';
GRANT SELECT, SHOW VIEW, RELOAD, SHOW DATABASES, LOCK TABLES, EVENT, TRIGGER ON *.* TO 'sqlbu'@'localhost';

MySQL Backup Script to backup all Databases including new DBs added in the future:

#!/bin/bash
#=================================================================
# Backup script for MySQL Databases - this script will
# backup all MySQL Databases including any future additional DB's
#=================================================================
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/var/mysqlbu/$TIMESTAMP"
MYSQL_USER="sqlbu"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="Some really long complex password"
MYSQLDUMP=/usr/bin/mysqldump
MAILTO="[email protected]"

mkdir -p "$BACKUP_DIR/mysql"

databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`

for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --events --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz"
done

ls -lh $BACKUP_DIR/* > /var/mysqlbu/mysqlbu.rpt
mail -s "MySQL BU Notification - $TIMESTAMP" -a "From: [email protected]" $MAILTO < /var/mysqlbu/mysqlbu.rpt
# Cleanup older directories than 60 days
find /var/mysqlbu/ -type d -mtime +60 -prune -exec rm -rf {} \;
#find $BACKUP_DIR/ -type d -mtime +60 -exec rm -rf {} \;

purge-old-kernels (Ubuntu)

If you have long-running Ubuntu systems (server or desktop), and you keep those systems up to date, you will, over time, accumulate a lot of Linux kernels.

Canonical’s Ubuntu Kernel Team regularly (about once a month) provides kernel updates, patching security issues, fixing bugs, and enabling new hardware drivers. The apt utility tries its best to remove unneeded packages, from time to time, but kernels are a little tricky, due to their version strings.

Over time, you might find your /boot directory filled with vmlinuz kernels, consuming a considerable amount of disk space. Sometimes, sudo apt-get autoremove will clean these up. However, it doesn’t always work very well (especially if you install a version of Ubuntu that’s not yet released).

What’s the safest way to clean these up? (This question has been asked numerous times, on the UbuntuForums.org and AskUbuntu.com.)

The definitive answer is:

sudo purge-old-kernels

You’ll already have the purge-old-kernels command in Ubuntu 16.04 LTS (and later), as part of thebyobu package.  In earlier releases of Ubuntu, you might need to install bikeshed, you can grab it directly from Launchpad or Github.

The info above is from Dustin Kirkland’s Blog – http://blog.dustinkirkland.com/2016/06/purge-old-kernels.html