Skip to content

Instantly share code, notes, and snippets.

@deviousway
deviousway / gist:852a01062b244206744a2c8edd1babad
Created October 8, 2021 06:44
Ansible remove dot from variable with version
php_version: 7.4
php_version_redhat: "{{ php_version | regex_replace ('[.~]', '') }}"
###Will return
###"msg": 74
@deviousway
deviousway / Listing all process swap space usage sorted.md
Last active August 17, 2018 01:50
Listing all process swap space usage sorted
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
@deviousway
deviousway / mysql_export_users_with_privileges_and_password.txt
Created August 5, 2018 10:23
mysql export users with privileges and password
#on old
mysqldump -udebian-sys-maint -p$PASSWORD mysql user > user_table_dump.sql
#on new
mysql -udebian-sys-maint -p$PASSWORD mysql < user_table_dump.sql
#login to mysql
mysql> flush privileges;
@deviousway
deviousway / migrate_debian.txt
Created August 4, 2018 20:07
migrate debian to debian
rsync -rtvzplogDH --numeric-ids --exclude=/etc/fstab --exclude=/etc/network/* --exclude=/proc/* --exclude=/tmp/* --exclude=/sys/* --exclude=/dev/* --exclude=/mnt/* --exclude=/boot/* /* root@$DESTINATION_HOST:/
@deviousway
deviousway / linux_migrate_users.txt
Last active October 1, 2018 03:32
linux copy/migrate users from one server to another
mkdir move/
export UGIDLIMIT=500
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
cp /etc/gshadow /root/move/gshadow.mig
scp -r /root/move/* user@new.linuxserver.com:/path/to/location
mkdir /root/newsusers.bak
@deviousway
deviousway / docker_cheat_sheet.md
Created June 23, 2018 13:51
docker cheat sheet

##how to show docker run line command

docker ps -a --no-trunc

@deviousway
deviousway / centos7_VPN_setup.md
Last active April 10, 2018 19:34
centos7 VPN setup

OpenVPN Setup

Install packages

yum  -y install epel-release 
yum --enablerepo=epel -y openvpn easy-rsa net-tools bridge-utils iptables-services mlocate wget htop nano

easy-rsa3 certificates

@deviousway
deviousway / exim_cheatsheet.md
Created March 16, 2018 08:48
exim_cheatsheet

Here are some useful things to know for managing an Exim 4 server. This assumes a prior working knowledge of SMTP, MTAs, and a UNIX shell prompt.

Message-IDs and spool files The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.

There are three -- count 'em, THREE -- files for each message in the spool directory. If you're dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all, and don't leave Exim with remnants of messages in the queue. I used to mess directly with these files when I first started running Exim machines, but thanks to the utilities described below, I haven't needed to do that in many months.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.

Files in /var/spool/exim/input are named after the mes

@deviousway
deviousway / sed.txt
Last active March 29, 2018 01:19
Sed replace line what contain
sed -i 's/domain1\.com/domain2\.com/d'
sed -i '/<?php/c\<?php'
#Add line (/n) after line what contain pattern
grep -rl 'pattern' public_html/ |xargs sed -i "s/1; ?>/1; ?>\n/g"
#remove line what contain
grep -rl 'pattern' public_html/ |xargs sed -i '/pattern/d'
@deviousway
deviousway / centos_static_ip.txt
Last active January 27, 2018 07:27
centos network innterface setup static ip
/etc/sysconfig/network-scripts/ifcfg-enp2s0
IPV6INIT=no
BOOTPROTO=static
DEVICE=enp2s0
ONBOOT=yes
UUID="ccea7d4f-855b-496e-945b-da7fe543b725"
IPADDR=104.193.150.10
NETMASK=255.255.255.248
GATEWAY=104.193.150.9