Skip to content

Instantly share code, notes, and snippets.

View D4R4's full-sized avatar

Dara Ardalan D4R4

  • SCALINX
  • Paris, France
View GitHub Profile
@D4R4
D4R4 / linux_find_replace
Created April 1, 2019 07:09
find and replace str in filename in a directory recursively
find . -name '*StR1*' -type f -exec bash -c 'mv "$1" "${1/StR1/StR2}"' -- {} \;
@D4R4
D4R4 / snmpd_centos
Last active May 14, 2019 03:11
SNMPD on CentOS
yum -y install net-snmp net-snmp-utils
firewall-cmd --zone=public --permanent --add-port=161/tcp
firewall-cmd --zone=public --permanent --add-port=161/udp
@D4R4
D4R4 / mysql_replace-text.sql
Created April 1, 2019 07:49
replace text in mysql text field
UPDATE
table_name
SET
column_name = REPLACE(column_name, 'text to find', 'text to replace with')
WHERE
column_name LIKE '%text to find%';
@D4R4
D4R4 / mysql_replace_from_another_table.sql
Created April 1, 2019 10:59
replace value with other column index as relation between tables
UPDATE prods
INNER JOIN cat_key ON (prods.cat = cat_key.name)
SET prods.cat = cat_key.id
@D4R4
D4R4 / reset_rx_counter.sh
Last active September 5, 2019 07:40
The script causes a reset in interface TX Packet bytes transfered which should be applied monthly to keep a correct billing record
sudo -- sh -c 'ifdown eth0 ; modprobe -r vmxnet3; modprobe vmxnet3 ; ifup eth0'
@D4R4
D4R4 / python_ip.py
Last active May 12, 2019 15:29
Python functions to mess around with IP Addresses and ranges, useful to prase data from directories like RIPE or etc.
import socket,struct
def makeMask(n):
"return a mask of n bits as a long integer"
return (2L<<n-1) - 1
def dottedQuadToNum(ip):
"convert decimal dotted quad string to long integer"
return struct.unpack('L',socket.inet_aton(ip))[0]
@D4R4
D4R4 / epel-release
Created May 8, 2019 15:56
Sometimes, in the CentOS 7 Live you get yum Repo erros after you install epel-release (for mounting VMDKs for example)
1. You should upgrade CURL
2. you better upgrade ca-certificates
3. install epel-release
4. install epel package
@D4R4
D4R4 / escape_space
Created May 8, 2019 16:35
Escape space in SCP command path
scp user@host:/path/to/directory\\\ with\\\ spaces/file ~/Downloads
@D4R4
D4R4 / rsync_cron
Created May 11, 2019 20:29
Rsync with remote site with cron consideration
pgrep -cx rsync || sshpass -p 'P@SSW0RD' rsync -avzP -e "ssh -p 4532" root@HOSTNAME:/var/www/dataroot/html/media /var/www/html
@D4R4
D4R4 / LVM_physical
Created May 14, 2019 03:11
extend a partition with a LVM and the contained physical volume and logical volume
1. Resize the partition (again, you can do this with the system running). GParted is easy to use and supports resizing.
You can also use a lower level tool such as fdisk. But you'll have to delete the partition and recreate it. Just make sure when doing so that the new partition starts at the exact same location.
2. partprobe or Reboot. Since the partition table was modified on the running system, it won't take effect until a reboot.
3. Run pvresize /dev/sdXY to have LVM pick up the new space.
4. Resize the logical volume with lvextend. If you want to use the whole thing, lvextend -r -l +100%FREE /dev/VGNAME/LVNAME. The -r will resize the filesystem as well.
Though I always recommend against using the entire volume group. You never know what you'll need in the future. You can always expand later, you can't shrink.