Posts

Debian - Install on BTRFS with Snapper Backups, GRUB-BTRFS and ZRAM

Start the Install Process  Boot the Debian install media Select Advanced Options Run through the installer until you get to "Partition Disks" Create the Partitions Select "Manual" Select the free space you are going to install Debian on Select "Create a new partition". This is the EFI partition Set the size to "512 MB" Change "Use as:" to "EFI System Partition" "Bootable flag:" should be "on" Select "Done setting up the partition" Create a 1GB, ext4 partition for /boot Set "Mount point:" to "/boot" Create another partition with the remaining free space Set "Use as:" to "btrfs journaling file system" Set "Mount point:" to "/" Select "Finish partitioning and write changes to disk" Do not create a swap partition. We are going to use ZRAM. Select "No" to continue Write the changes to disk Create the BTRFS System and Subvol...

Docker

Sum the size of dangling docker images docker images --format "{{.Size}}" --filter=dangling=true | awk '{sub(/B$/,""); print $1 }' | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}' | numfmt --to=iec

Find Which Processes are Using Swap

I was doing s ome testing on my Virtuozzo linux VPS and wanted to find what was using the swap. The short version is that processes that have not been used in a long time will be moved into swap to free up RAM. I found the following page with a one-liner to show the running processes and the amount of swap they are using (including processes with 0 kB of swap).  https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/  I modified the one-liner to only show processes using swap. for file in $(grep -El "VmSwap:\s+[1-9][[:digit:]]* kB" /proc/*/status) ; do awk '/Name:|VmSwap:/{printf $2 " " $3}END{ print "" }' $file; done | sort -k2nr php-fpm 488792 kB php-fpm 485172 kB php-fpm 475640 kB php-fpm 469504 kB php-fpm 469100 kB php-fpm 462044 kB php-fpm 439604 kB php-fpm 430868 kB php-fpm 410124 kB php-fpm 389892 kB php-fpm 381132 kB php-fpm 380136 kB php-fpm 379988 kB php-fpm 379216 kB php-fpm 316296 kB mysqld 225884 kB php-fpm 92096 kB php-fpm 91...

Excel - Combine Multiple CSV Files

Open a blank workbook Select the Data menu Select Get Data -> From File -> From Folder Select "Browse..." and navigate to the folder containing the CSV files Select "OK" Select "Transform Data" Use the filter in the 3rd column (Name) to deselect any files you do not want included in the dataset Click the double arrow icon (Combine Files) on the right of the 2nd column (Content) Select "OK" Select the "Source.Name" column Select "Remove Columns" from the Ribbon Ensure the first column of data is highlighted Select Remove Rows -> Remove Blank Rows from the Ribbon Select "Close & Load" from the Ribbon You can now save the combined files as a CSV file.

YumRepo Error: All mirror URLs are not using ftp, http[s] or file

A very old server that had a service dependant on CentOS 5 Running any yum command resulted in yum check-update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile YumRepo Error: All mirror URLs are not using ftp, http[s] or file.  Eg. Invalid release/repo/arch combination/ YumRepo Error: All mirror URLs are not using ftp, http[s] or file.  Eg. Invalid release/repo/arch combination/ YumRepo Error: All mirror URLs are not using ftp, http[s] or file.  Eg. Invalid release/repo/arch combination/ The answer was that the mirrorlists needed to be updated to point at the last version of CentOS 5. Stolen from here:  https://www.linuxquestions.org/questions/centos-111/yumrepo-error-centos-5-9-a-4175604669/#post5704920 echo "http://vault.centos.org/5.11/os/x86_64/" > /var/cache/yum/base/mirrorlist.txt echo "http://vault.centos.org/5.11/extras/x86_64/" > /var/cache/yum/extras/mirrorlist.txt echo "http://vault.centos.org/5.11/updat...

Plesk - Decrypt FTP Passwords

I was working on a project where Plesk user details were being imported into a database and it would help to know the password. Since Plesk 11 the Plesk Client account is hashed which makes it unrecoverable, but other passwords are encrypted with 128 bit AES encryption and a salt. If the FTP login name is the same as the client login there is a chance the customer was lazy and used the same details. To decrypt the passwords you will need the server secret key and the password string from the plesk database. The server secret key can be retrieved with the following command on a linux server: cat /etc/psa/private/secret_key | base64 Matching FTP logins (and their encrypted password) can be retrieved from the Plesk database with: SELECT REPLACE(s.home, '/var/www/vhosts/', '') AS domain, c.login, a.password FROM clients c LEFT JOIN sys_users s ON s.login = c.login LEFT JOIN accounts a on s.account_id = a.id; The results will look like: +-------------------...

MySQL - Sort by IP Address

If you have a column containing ip addresses, sort the ip addresses numerically with: ORDER BY  INET_ATON(ip_address_column)

systemctl: Show running services

systemctl list-units --type service --state running

Google Maps API: Allow local files from your desktop computer

Assuming that you have already created the key... Go to https://console.developers.google.com/apis/credentials Make sure you have the right project selected from the dropdown at the top Click the API Key Under "Application restrictions" select "HTTP referrers (websites)" Under "Website restrictions" click "ADD AN ITEM" Put __file_url__//*  into the box that appears Click "SAVE"

IPTables: Clear all rules

When you need to clear all rules and set the default police to ACCEPT. iptables-save | sed "/-/d;/^#/d;s/DROP/ACCEPT/" | iptables-restore This is not permanent. The default rules will be reloaded if IPTables, your firewall or the server is restarted.

MySQL/Percona: Show the order of configuration files

Show which files the database server uses and the order they are read. Get the server binary location # which mysqld /usr/sbin/mysqld Get the configuration file locations and order # /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options" Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

Excel: Strikethrough Shortcut

Ctrl + 5 Easier than having to go into the Font -> Extended menu every time.

Google Chrome: Manage Flash Sites

Image
The HTML5 client for VMware is missing some functionality so I need to run the Flash client in Google Chrome. I normally run the Canary or Dev channels of Chrome and the ability to add or block a sites ability to run Flash seems to have disappeared from Settings -> Advanced -> Content Settings -> Flash. It is still there in the Stable channel. My default Flash setting in all is "Ask First", but nothing happens in  Canary and Dev As per the instructions on: https://support.google.com/chrome/answer/6258784?co=GENIE.Platform%3DDesktop&hl=en The site needs Flash to work If a website isn’t working, you might need to change your settings to allow Flash. To the left of the web address, click Lock   or Info  . At the bottom, click Site Settings. In the new tab, to the right of "Flash," click Allow. Go back to the site and reload the page.

Linux: Permanent CIFS/SMB mount

I needed to permanently mount a directory on a Windows server that had spaces in the path. I also wanted to use a credentials file so that the remote server username and password would not be in the world readable fstab file. The following was cobbled together from: Mount samba shares with utf8 encoding using cifs and: Mount password protected network folders Create a credentials file (as root) containing the username and password and restrict it's ability to be read by other users (/etc/fstab is world readable). vi /root/.smbcredentials username=someusername password=somepassword Save and exit the file. Change the file permissions to only be readable by root. chmod 600 /root/.smbcredentials Update the fstab file Add the following line to /etc/fstab (spaces are replaced with \040  or the mount will fail) // ip address / c$/Program\040Files/Microsoft\040SQL\040Server/ /var/backups/Server cifs credentials=/root/.smbcredentials,iocharset=utf8,sec=ntlm 0 0 Exit ...

FreeBSD: Increment the serial number of every zone file by 1

I needed to increment the serial number of every zone on a master server to trigger an update to a new slave. Since I know next to nothing about csh the easiest way was the following one liner in sh: for i in `ls -1 | xargs`; do j="`awk '$3 == "Serial"{print $1 + 1}' $i`"; sed -i "" "s/^[[:digit:]]\{10\}\([[:space:]]\;[[:space:]]Serial\)/$j\1/" $i; echo -n "$i "; rndc reload $i; sleep 2; done

Linux: Display Hard Drive Serial Number For Each Device

I needed to physically replace a drive in an array and to do that I needed the serial number of the drive. for i in $(awk '/sd[a-z]+$/ { print $4 }' /proc/partitions | sort); do printf "%-5s%s\n" $i "$(smartctl -i /dev/$i | grep Serial | sed 's/^[^:]\+:[[:space:]]\+\([[:alnum:]\-]\+\)/\1/')"; done sda  WD-WXL708065381 sdaa Z1F1HLJN sdb  Z1F0YPP2 sdc  Z1F136GZ sdd  Z1F0X9X7 sde  Z1F136DE sdf  Z1F1HM91 sdg  9WM66QZP sdh  9WM73LV3 sdi  9WM6JLJT sdj  9WM73600 sdk  9WM6Y6B5 sdl  Z1F1HLMY sdm  9XH024P1 sdn  9XH025HS sdo  9XH01Y60 sdp  9XH025PY sdq  9WM6KMP3 sdr  9WM6PESG sds  9WM6QFZP sdt  9WM66ZY9 sdu  9WM6SAL6 sdv  Z1F1LVP2 sdw  Z1F11NKT sdx  Z1F11LB7 sdy  Z1F11NVV sdz  Z1F11MEF

Postfix: Delete from queue by header content

Normally you can use mailq to delete by sender or receipient, but postfix doesn't really have any tools to delete based on any other content in the email. Following is a quick and nasty one liner that I came up with to help a customer out. One of the websites he hosted had been compromised and was being used to send out spam. The only thing the emails had in common was a header. X-PHP-Originating-Script: 33:index2Xv6C.php for i in $(mailq | tail -n +2 | awk 'BEGIN { RS = "" } $1 ~ /^[[:alnum:]]/ { print $1 } ' | tr -d '*!' ); do if [[ $(postcat -hq "$i" | grep index2Xv6C.php) ]] ; then postsuper -d $i; fi; done It wasn't particularly quick but it didn't cause much load either.

Cron jobs running in UTC timezone on Virtuozzo 4.0 containers

Symptoms / etc / crontab showed that cron . daily should be running at 05:08 in the morning, but a grep of the syslogs showed that it was running at 18:08 at night. # grep daily / etc / crontab 8 5 * * * root test -x / usr / sbin / anacron || ( cd / && run-parts --report / etc / cron . daily ) # grep daily / var /log/ syslog . 0 Mar 25 18:08:01 vps /USR/SBIN/CRON [ 8110]: (root) CMD (test -x / usr / sbin / anacron || ( cd / && run-parts --report / etc / cron . daily )) The 'date' command showed the right timezone. # date Tue Mar 26 16:56:00 NZDT 2013 Cause / etc / timezone was malformed by having the the local timezone  appended, instead of overwritten, in the final stages of customisation  by Virtuozzo, when the container was installed. # cat / etc / timezone   Etc /UTC Pacific/Auckland Solution Removing the bogus "Etc/UTC" line from / etc / timezone fixed the problem.

Useful RDP Keyboard Shortcuts

CTRL+ALT+END : Open the Microsoft Windows Security dialog box (CTRL+ALT+DEL) ALT+PAGE UP : Switch between programs from left to right (CTRL+PAGE UP) ALT+PAGE DOWN : Switch between programs from right to left (CTRL+PAGE DOWN) ALT+INSERT : Cycle through the programs in most recently used order (ALT+TAB) ALT+HOME : Display the Start menu (CTRL+ESC) CTRL+ALT+BREAK : Switch the client computer between a window and a full screen ALT+DELETE : Display the Windows menu CTRL+ALT+Minus sign : Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer (ALT+PRT SC) CTRL+ALT+Plus sign : Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer (PRT SC)

Add Multiple IP Addresses to a Windows Server From the Command Line

Say you want to add 192.168.1.2 through to 192.168.1.14 with a /28 netmask (255.255.255.240). for /L %a in (2,1,14) do netsh in ip add address "Local Area Connection" 192.168.1.%a 255.255.255.240 Which is: for /L (tell for that it's a range of numbers) %a in (placeholder variable) (start, step, end) (self explanatory) do (command goes here) This page FOR /L has more detail and is part of this very useful site ss64.com