Skip to content

Instantly share code, notes, and snippets.

View liyang85's full-sized avatar

Yang Li liyang85

View GitHub Profile
@liyang85
liyang85 / yum-install-pip-centos7.sh
Last active June 13, 2017 07:15
How to Install Pip on CentOS 7
# copy from https://www.liquidweb.com/kb/how-to-install-pip-on-centos-7/
# First, we’ll install the EPEL repository
yum install epel-release
# As a matter of best practice we’ll update our packages:
yum -y update
yum -y install python-pip
# Check the version of Pip that is installed:
@liyang85
liyang85 / essential-settings-after-centos69-minimal-installation.sh
Last active July 13, 2017 06:06
最小化安装CentOS 6.9之后的必要设置
# Part 1: network
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.ori
sed -i 's/ONBOOT=no/ONBOOT=yes/; s/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '$a IPADDR=192.168.6.240\nPREFIX=24\nGATEWAY=192.168.6.1' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '$a DNS1=223.5.5.5\nDNS2=119.29.29.29' /etc/sysconfig/network-scripts/ifcfg-eth0
ifdown eth0 && ifup eth0
# If you use a VMware cloned virtual machine, you'll see an error:
# `Device eth0 does not seem to be present, delaying initialization.`, you can change DEVICE name and HWADDR to solve it.
cat /etc/udev/rules.d/70-persistent-net.rules
@liyang85
liyang85 / compile-php-5.3.27-and-run-as-fastcgi-mode.sh
Last active April 8, 2020 13:46
Compile php-5.3.27 and run as FastCGI mode with Nginx & MySQL
cd /home/oldboy/tools
# 1. Install dependencies
# Part 1: yum install
yum install -y \
freetype-devel \
gd-devel \
libcurl-devel \
libjpeg-turbo-devel \
libpng-devel \
@liyang85
liyang85 / yum-install-fail2ban-on-centos6.sh
Created August 17, 2017 04:23
Install Fail2ban to protect SSH on CentOS 6
# part 1: installation
yum install epel-release
yum install fail2ban
# part 2: configure local settings
#
# You can find a file with default values called `/etc/fail2ban/jail.conf`.
# Since this file may be overwritten by package upgrades, we shouldn't edit it in-place.
# Instead, we'll write a new file called `/etc/fail2ban/jail.local`.
@liyang85
liyang85 / change-hostname-on-centos.sh
Created September 13, 2017 06:47
Change hostname on CentOS
# Part 1: CentOS 6
vim /etc/sysconfig/network
HOSTNAME=my_hostname
source /etc/sysconfig/network
# `hostname` can set the host name until reboot,
# it also can show the host name
hostname
@liyang85
liyang85 / .cvimrc
Last active August 6, 2018 02:36
my .cvimrc for cVim extension of Google Chrome
set noautofocus
let blacklists = ["https://checkvist.com/*","https://inbox.google.com/*","https://calendar.google.com/*","https://drive.google.com/*","https://keep.google.com/*","https://mail.google.com/*","https://mubu.com/*","https://leanote.com/*","https://docs.google.com/*","https://mynoise.net/*","https://onedrive.live.com/*","https://kiwivm.64clouds.com/*","https://dida365.com/*","http://localhost/*","https://dynalist.io/*","http://cv.ftqq.com/*","https://todoist.com/*","https://www.youtube.com/*"]
let mapleader = ","
map <Leader>x :restore<Space>
" You can use <Space>, which is interpreted as a
" literal " " character, to enter buffer completion mode
@liyang85
liyang85 / Validating an IP Address.md
Last active November 25, 2017 12:48
①首先验证输入的IP是由圆点分成的四段,且每段内容为1-3位数字 ②然后把四段内容用圆点分隔,存入数组 ③最后验证数组每一个元素小于等于255 http://www.linuxjournal.com/content/validating-ip-address-bash-script

To belabor the obvious: IP addresses are 32 bit values written as four numbers (the individual bytes of the IP address) separated by dots (periods). Each of the four numbers has a valid range of 0 to 255.

The following bash script contains a bash function which returns true if it is passed a valid IP address and false otherwise. In bash speak true means it exits with a zero status, anything else is false. The status of a command/function is stored in the bash variable "$?".

#!/bin/bash

# Test an IP address for validity:
# Usage:
#      valid_ip IP_ADDRESS
@liyang85
liyang85 / validation (name and IP address) in bash.sh
Created November 25, 2017 12:49
另一种验证IP的方法。要点: ①直接把变量值包含的空格替换为下划线 ②匹配IP的正则表达式要更具体 ③在Bash中测试regex **不要** 使用任何引号! https://stackoverflow.com/a/13015572/3025050
#!/bin/bash
read name
while [[ ! "$name" =~ '[A-Za-z ]' ]]; do
read -p "Wrong name format. Re-enter: " name
done
name="${name// /_}"
read ip
@liyang85
liyang85 / Extract one file from an rpm package.sh
Created December 3, 2017 13:44
must use rpm2cpio and cpio, or no other way can do this.
# find the target file in the package
rpm2cpio httpd-2.2.15-59.el6.centos.x86_64.rpm | cpio -tv | grep "init.d/httpd"
# view content of the target file then redirect it
rpm2cpio httpd-2.2.15-59.el6.centos.x86_64.rpm | cpio -i --to-stdout ./etc/rc.d/init.d/httpd > /etc/rc.d/init.d/httpd
@liyang85
liyang85 / Compile GNU Screen 4.6.2 in CentOS 6.sh
Created December 3, 2017 13:45
CentOS 6 shipped Screen 4.00.03 cannot support vertical split region!
yum -y install ncurses-devel
./configure
make && make install
install -m 644 etc/etcscreenrc /etc/screenrc