分类 Linux 中的文章

Awk常用命令

  1. 列出最常的十条命令: history | awk '{$1="";print $0}' | awk '{a[$0]++}END{for(i in a){print a[i],i}}' | sort -rn |head

    ……

    阅读全文

curl命令手册

curl --location --request GET 'https://test.abc.com/v1/health' --header 'Authorization: Apikey 20220602'

-H "Content-Type: application/json"

-d "{ \"claimStatus\": 0, \"lastBillMonth\": 202208, \"occurDateTime\": \"2022-09-01 00:00:00\"}"

curl -k --resolve foo.bar:443:127.0.0.1 'https://foo.bar/foobar' -v -so /dev/null -w '%{size_download}' 

curl -H 'Host: web-host' http://192.168.1.100

curl $KUBE_API/apis/apps/v1/deployments \
  --cacert ~/.minikube/ca.crt \
  --cert ~/.minikube/profiles/cluster1/client.crt \
  --key ~/.minikube/profiles/cluster1/client.key


for i in `cat url.txt`
do
    code=`curl -o /dev/null -s -w "%{http_code}" $i`
    if [ $code != 200 ];then
        curl -H "Content-Type: application/json;charset=utf-8" \
             -d "{'msgtype': 'text','text': {'content': $i, '预发环境: 地址异常'}}" \
             https://oapi.dingtalk.com/robot/send?access_token=15026b8e5b68ec
    fi
done

curl --insecure https://www.example.com -H 'X-Forwarded-For: 1.1.1.1'

curl --user "gwy:Q1" guowy-cloud-eureka-server-0.eureka-headless.default.svc.cluster.local:8080
curl -u guowy: -X POST http://pre-prometheus..com/-/reload

curl -L -w "namelookup: %{time_namelookup}\nconnect: %{time_connect}\nappconnect: %{time_appconnect}\npretransfer: %{time_pretransfer}\nstarttransfer: %{time_starttransfer}\ntotal: %{time_total}\n" https://example.com/
……

阅读全文

Shell知识点合集

  1. 数组
1
2
3
4
5
arr=(str1 str2 str3)
for i in ${arr[@]}
do
echo $i
done
  1. 预定义变量
1
2
3
4
5
6
$# 表示命令中位置参数的数量
$* 表示所有的位置参数的内容
$? 表示命令执行后的返回的状态,用于检查上一个命令的执行是否正确。在linux中,命令退出状态为0表示命令执行正确,任何非0值的表示命令执行错误。
$$ 表示当前进程的进程号
$! 表示后台运行的最后一个进程的进程号
$0 所有参数
  1. 测试语句
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-eq Equal to = Equal to   
-ne Not equal to != Not equal to
-lt Less than \< Less than (ASCII) *
-le Less than or equal to
-gt Greater than > Greater than (ASCII) *
-ge Greater than or equal to
re-directs output of one file to another.
-a file
True if file exists.
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-g file
True if file exists and is set-group-id.
-h file
True if file exists and is a symbolic link.
-k file
True if file exists and its ``sticky'' bit is set.
-p file
True if file exists and is a named pipe (FIFO).
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t fd True if file descriptor fd is open and refers to a terminal.
-u file
True if file exists and its set-user-id bit is set.
-w file
True if file exists and is writable.
-x file
True if file exists and is executable.
-G file
True if file exists and is owned by the effective group id.
-L file
True if file exists and is a symbolic link.
-N file
True if file exists and has been modified since it was last read.
-O file
True if file exists and is owned by the effective user id.
-S file
True if file exists and is a socket.
file1 -ef file2
True if file1 and file2 refer to the same device and inode numbers.
file1 -nt file2
True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.
file1 -ot file2
True if file1 is older than file2, or if file2 exists and file1 does not.
-o optname
True if the shell option optname is enabled. See the list of options under the description of the -o option to the set builtin below.
-v varname
True if the shell variable varname is set (has been assigned a value).
-z string
True if the length of string is zero.
string
-n string
True if the length of string is non-zero.
  1. 发送邮件
1
2
echo "content" | mail -s title 1248247511@qq.com
#mail 命令依赖 yum install mailx
  1. 计算
1
2
echo `expr 1 + 1`
echo "1+3","ALL" | bc
  1. 函数

函数的定义和调用

……

阅读全文

Inotify_rsync_unison使用记录

inotifywait

1
/usr/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w %f %e' -e create,delete,modify,move --exclude "\.(tmp|swp|log|info)" $mon_file >> $log_file

rsync

1
2
3
4
5
6
7
8
9
#!/bin/bash

[ ! -e 'exclude.list' ] && echo 'No exclude.list file, exit.' && exit 100

rsync -avz --delete --exclude-from=exclude.list /usr/local/sonatype-work 192.168.1.1:/usr/local

echo "`date +%Y-%m-%d" "%H:%M:%S` -- sync done." >> /var/log/rsync.log

echo "----------------------------------------------------------" >> /var/log/rsync.log

–delete参数会删除源目标没有的文件,等于覆盖 –exclude-from=exclude.list, exclude.list文件是相对路径

……

阅读全文