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. 函数

函数的定义和调用

……

阅读全文

Mysql命令合集

# 连接
shell# mysql -h$ip -P$port -u$user -p

#查看binlog文件
mysql> show binary logs;

#查看binlog内容
mysql> show binlog events in 'mysql-bin.001294';

#刷新生成新的binlog文件
mysql> flush logs;

#删除binlog
> PURGE MASTER LOGS TO 'MySQL-bin.010';  //清除MySQL-bin.010日志
> PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00';   //清除2008-06-22 13:00:00前binlog日志
> PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);  //清除3天前binlog日志BEFORE,变量的date自变量可以为'YYYY-MM-DD hh:mm:ss'格式。

# 查看binglo详细信息(比如binlog为row格式的),position可以通过show binlog events确认.
shell# mysqlbinlog -vv .\data\binlog.000013 --start-position=2738 --stop-position=2973;

#全局锁
mysql> Flush tables with read lock;


mysql> show engine innodb status

mysql> show variables like 'transaction_isolation';


alter table t engine = InnoDB # 重建表
analyze table t 其实不是重建表,只是对表的索引信息做重新统计,没有修改数据,这个过程中加了 MDL 读锁;
optimize table t 等于 recreate+analyze。

#备份
mysqldump -uroot --single-transaction --master-data=2 --routines --striggers --events --set-gtid-purged=OFF --all-databases -p > /tmp/t.sql
……

阅读全文

金融云VPN新建用户操作步骤-管理员版本

标签(空格分隔): 金融云 vpn


1. 下载风云令

2. 登录VPN自助控制台

  • 在“我的VPN”里记住客户端IP列表
  • 然后在“终端管理”—>“添加终端用户”,完成用户添加(SN可通过风云令获取)
  • 添加完后可以在“我的VPN”里头看到多出一个ip地址,此地址即为新分配给自己的地址

3. 修改入站规则

  • 在云服务ecs->安全组->名称为ssh的列表->配置规则->内网入方向中找到端口22的规则列表->克隆规则,将授权对象改为自己分配到的ip地址即可

4. 设置密码

  • 按提示操作即可,第一次密码输入风云令动态码,然后输入两次自设密码,最后输入密码+风云令动态码即可

5. 账号设置完成,下载VPN客户端“AG系列产品"完成登陆

  • 客户端域名: vpn.jbp.aliyun.com
  • 用户名记得加@domain.com后缀
  • 端口443
  • 登录密码为密码+风云令动态码
  • 其他默认设置即可

注: 风云令APP的有自带时间校验功能,如果时间不同可能造成登录失败。 更加详细的官网文档地址:VPN自助管理控制台 页面找到帮助入口。

……

阅读全文

金融云VPN新用户申请操作步骤-普通用户版

标签(空格分隔): 金融云 vpn


1. 下载风云令, 将风云令sn序列号发给管理员

2. 待管理员为自己开好账号后自己即可设置密码

  • 按提示操作即可,第一次密码输入风云令动态码(完整账号为“帐号@.com”),然后输入两次自设密码,最后输入密码+风云令动态码即可
  • 操作完成可关闭网页

3. 账号设置完成,下载VPN客户端完成登陆

  • 客户端域名: vpn.jbp.aliyun.com
  • 端口为443
  • 用户名记得加@qi.com后缀
  • 登录密码为密码+风云令动态码
  • 其他默认设置即可

注: 风云令APP的有自带时间校验功能,如果时间不同可能造成登录失败。

……

阅读全文

Jenkins_library_err

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (org.jenkinsci.plugins.workflow.cps.CpsClosure2 getCode). 

### Administrators can decide whether to approve or reject this signature.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (org.jenkinsci.plugins.workflow.cps.CpsClosure2 getCode)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:270)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:160)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:143)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:30)

进入jenkins的【系统管理】–>【脚本命令行】,然后你应该就会明白了。

……

阅读全文

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文件是相对路径

……

阅读全文

nginx安全设置

  1. 添加认证
yum install httpd-tools

htpasswd -c -b /etc/nginx/passwd/kibana.passwd user

auth_basic "Kibana Auth";
auth_basic_user_file /etc/nginx/passwd/kibana.passwd;
  1. 更改默认超时时间
client_header_timeout 20s;   #读取客户端请求头超时时间,默认60s
client_body_timeout 10s;     #读取客户端body超时时间,默认60s
send_timeout 30s;            #服务端向客户端传输数据的超时时间,默认60s

增加上面三个参数,增强抵抗Slow HTTP Denial of Service Attack 能力
  1. 黑名单功能 location字段中增加IP黑名单
if ($http_x_forwarded_for ~ 192.168.1.14|192.168.1.5|192.168.2.23) {
    return 403;
}

http指令内

……

阅读全文

安全工具

拓扑分析工具:DNS Sweep、Nslookup等 自动化扫描工具:、Nessus、AIScanner等 端口扫描、服务检测:Nmap、SuperScan等 密码、口令破解:John the ripper、L0phtcrack、MD5 Crack、Cain等 嗅探分析工具:Ethereal、Entercap、Dsniff等 Exploiting 利用工具:Metasploit Framework、Core Impact、Canvas等 应用缺陷分析工具:SQLMAP等

……

阅读全文

Word新建标题

  1. 视图 –> 导航窗格,显示标题

  2. 在标题行回车后会出现什么(如2.2 test,调整大纲级别为2级后)

    ……

阅读全文