linux cmd¶
awk¶
awscurl¶
export AWS_DEFAULT_REGION=us-east-2
export AMP_QUERY_ENDPOINT=https://aps-workspaces.us-east-2.amazonaws.com/workspaces/ws-xxx/api/v1/query
awscurl -X POST --region ${AWS_DEFAULT_REGION} --service aps \
"${AMP_QUERY_ENDPOINT}" -d 'query=prometheus_tsdb_head_series' \
--header 'Content-Type: application/x-www-form-urlencoded'
awscurl -X POST --region ${AWS_DEFAULT_REGION} --service aps \
"${AMP_QUERY_ENDPOINT}" -d 'query=up&time=1652382537&stats=all' \
--header 'Content-Type: application/x-www-form-urlencoded'
query=sum+%28rate+%28go_gc_duration_seconds_count%5B1m%5D%29%29&start=1652382537&end=1652384705&step=1000&stats=all
install¶
brew¶
- install
column¶
curl¶
- curl-sample-1
- badssl.com
check http return code¶
datediff¶
ec2-instance-selector¶
envsubst¶
var1=string1
var2=string2
cat >$$.yaml <<-'EOF'
$var1
$var2
$var3
EOF
export var1 var2
cat $$.yaml |envsubst '$var1 $var2' > $$-new.yaml
- refer envsubst
ffmpeg¶
fio¶
firewall-cmd¶
function¶
less or no parameters¶
- 在 func 中定义 local 变量,export 后在 func 外部依然无法访问
parse parameter¶
c:p:
参数 c 和 p 都需要参数
cp
参数 c 和 p 都不需要参数
function parsepara () {
OPTIND=1
OPTSTRING="h?v:c:p:"
local VPC_ID=""
local VPC_CIDR=""
local PORTS=()
while getopts ${OPTSTRING} opt; do
case "${opt}" in
v) VPC_ID=${OPTARG} ;;
c) VPC_CIDR=${OPTARG} ;;
p) PORTS+=("${OPTARG}") ;;
h|\?)
echo "format: create-sg -v VPC_ID -c VPC_CIDR [-p PORT1] [-p PORT2]"
echo -e "\tsample: create-sg -v vpc-xxx -p 172.31.0.0/16"
echo -e "\tsample: create-sg -v vpc-xxx -p 0.0.0.0/0 -p 80 -p 443"
return 0
;;
esac
done
: ${VPC_ID:?Missing -v}
: ${VPC_CIDR:?Missing -c}
echo "CIDR:"${CIDR}
echo "PORTS:"${PORTS}
echo "PORTS[@]"${PORTS[@]}
for i in ${PORTS[@]:--1}; do
echo "i:"$i
done
}
history¶
bash # open a new session.
unset HISTFILE # avoid recording commands to file.
commands not recorded
.
.
exit
imagemagick¶
ip-forward-¶
echo 'net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.accept_source_route = 0
' |tee -a /etc/sysctl.conf
sysctl -p
ip-public¶
iptables-¶
MASQUERADE-¶
iptables¶
yum install iptables-services -y;
# Start and configure iptables:
systemctl enable iptables;
systemctl start iptables;
# Configuration below allows allows all traffic:
# Set the default policies for each of the built-in chains to ACCEPT:
iptables -P INPUT ACCEPT;
iptables -P FORWARD ACCEPT;
iptables -P OUTPUT ACCEPT;
# Flush the nat and mangle tables, flush all chains (-F), and delete all non-default chains (-X):
iptables -t nat -F;
iptables -t mangle -F;
iptables -F;
iptables -X;
# Configure nat table to hairpin traffic back to GWLB:
iptables -t nat -A PREROUTING -p udp -s $gwlb_ip -d $instance_ip -i eth0 -j DNAT --to-destination $gwlb_ip:6081;
iptables -t nat -A POSTROUTING -p udp --dport 6081 -s $gwlb_ip -d $gwlb_ip -o eth0 -j MASQUERADE;
# Save iptables:
service iptables save;
lsblk-¶
network monitor¶
iperf¶
- https://aws.amazon.com/premiumsupport/knowledge-center/network-throughput-benchmark-linux-ec2/
- server
- client
openssl¶
compile
encryption¶
- encrypt on mac
- decrypt on linux
parallel¶
touch 1024 files, with parallel 128, filename will test-1, test-2, etc.
time seq 1 1024 | parallel --will-cite -j 128 touch /mnt/efs/01/tutorial/touch/${directory}/test-1.4-{}
regctl¶
rsync¶
notable folder¶
sync to s3¶
upload only md file to s3
- –exclude 参数必须放在 –include 参数之前。
- 如果您需要上传多个类型文件,可以使用多个 –include 参数。
work-notes¶
bash
export HISTSIZE=0
cd ~/Documents/
rsync -avr --delete \
./work-notes \
./SA-Baseline-50-12 \
./customers \
stevenpan@10.68.69.100:/Users/stevenpan/Documents/
sed¶
file=file.md
gsed -i 's/^!\[\[\([^]]\+\)\]\]/![](\1)/' ${file}
# change
# ![[stream-k8s-control-panel-logs-to-s3-21.png]]
# to
# ![](stream-k8s-control-panel-logs-to-s3-21.png)
sponge & tee & redirect to same file¶
sponge reads standard input and writes it out to the specified file. Unlike a shell redirect, sponge soaks up all its input before opening the output file. This allows constructing pipelines that read from and write to the same file.
ssh¶
stress-ng¶
container¶
apiVersion: apps/v1
kind: Deployment
metadata:
name: cpu-stress-deployment
spec:
replicas: 1
selector:
matchLabels:
app: stress-ng
template:
metadata:
labels:
app: stress-ng
spec:
containers:
- name: stress-ng-container
image: polinux/stress-ng # progrium/stress
command:
- 'sh'
- '-c'
- |
while true ; do
echo "start stress (10 min)"
stress-ng --cpu 2 --timeout 600
echo "start sleep (10min)"
sleep 600
done
resources:
limits:
cpu: "1"
requests:
cpu: "1"
tar¶
tcp setting - TIME_WIAT¶
net.ipv4.tcp_fin_timeout = 30
net.ipv4.ip_local_port_range = 15000 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_forward=1
net.ipv4.conf.all.accept_source_route = 1
tc - traffic control¶
doc¶
scenario¶
ts¶
add timestamp at the front of every command output
vim¶
wscat-¶
xfs¶
xfs-mount-¶
get uuid¶
xtop¶
- top
- htop
- atop
- iftop