“Shell基础”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
(未显示同一用户的6个中间版本)
第85行: 第85行:
 
=shell脚本特殊符号=
 
=shell脚本特殊符号=
 
[https://www.cnblogs.com/xuxm2007/archive/2011/10/20/2218846.html shell脚本中一些特殊符号]
 
[https://www.cnblogs.com/xuxm2007/archive/2011/10/20/2218846.html shell脚本中一些特殊符号]
 +
 +
= MySQL backup shell script =
 +
https://fedingo.com/shell-script-to-backup-mysql-database/
 +
 +
https://www.fosstechnix.com/shell-script-for-mysql-database-backup/
 +
 +
https://gist.github.com/lon-io/9067f746cd8cce10af4c52179c7e9b7e
 +
 +
https://orahow.com/linux-shell-script-for-mysql-database-backup/
  
 
= shell规范=
 
= shell规范=
 +
 +
https://www.shellcheck.net/
 +
 +
[https://chegva.com/3977.html Shell编程规范实践指南]
 +
 +
[https://www.cnblogs.com/thatsit/p/shell-jiao-ben-shu-xie-gui-fan.html Shell脚本书写规范]
 +
 
[https://www.iterdaily.com/post/shell-script-flavor/ shell书写规范建议]
 
[https://www.iterdaily.com/post/shell-script-flavor/ shell书写规范建议]
 +
 +
[https://blog.csdn.net/lihonghai2392/article/details/77915439  shell脚本编写规范(超实用)]
  
 
=see also=
 
=see also=
第93行: 第111行:
 
[https://blog.csdn.net/qq_45019159/article/details/104258887  Linux运维处理及监控脚本]
 
[https://blog.csdn.net/qq_45019159/article/details/104258887  Linux运维处理及监控脚本]
  
 +
 +
[https://www.centoschina.cn/course/introduction/9527.html  CentOS下查看cpu,内存,硬盘等硬件信息的方法 ]
 +
 +
[https://blog.csdn.net/cd15109139570/article/details/80316911  linux系统中的shell脚本||脚本常用的命令]
  
 
[https://blog.csdn.net/weixin_39887925/article/details/116693709  linux运维脚本开发工具,送给运维人员的8个编写脚本的建议]
 
[https://blog.csdn.net/weixin_39887925/article/details/116693709  linux运维脚本开发工具,送给运维人员的8个编写脚本的建议]

2022年2月18日 (五) 02:58的版本

Shell札记

IF条件判断,判断条件


1 字符串判断

str1 = str2      当两个串有相同内容、长度时为真
str1 != str2      当串str1和str2不等时为真
-n str1        当串的长度大于0时为真(串非空)
-z str1        当串的长度为0时为真(空串)
str1           当串str1为非空时为真

2 数字的判断

int1 -eq int2    两数相等为真
int1 -ne int2    两数不等为真
int1 -gt int2    int1大于int2为真
int1 -ge int2    int1大于等于int2为真
int1 -lt int2    int1小于int2为真
int1 -le int2    int1小于等于int2为真

3 文件的判断

-r file     用户可读为真
-w file     用户可写为真
-x file     用户可执行为真
-f file     文件为正规文件为真
-d file     文件为目录为真
-c file     文件为字符特殊文件为真
-b file     文件为块特殊文件为真
-s file     文件大小非0时为真
-t file     当文件描述符(默认为1)指定的设备为终端时为真

3 复杂逻辑判断

-a         与
-o        或
!        非

SHELL学习笔记----IF条件判断,判断条件


避免shell脚本被同时运行多次

利用$0 排除自身

#!/bin/bash
root@evan-ThinkPad-Edge:~# cat /home/evan/tunnel 
CPID=$$   #$$ 是脚本运行的当前进程ID号
RUN="`ps -ef | grep "$0" | grep -v "grep" | grep -v "$CPID" | wc -l`"  #$0 是脚本本身的名字
[ "$RUN" -gt 1 ] && exit
ssh -i /home/evan/.ssh/id_rsa -p 22 -qtfnN -D 7070  [email protected]


lockfile

LOCK_FILE="/tmp/my.lock"
if [[ -e $LOCK_FILE ]] ; then
echo "re-entry, exiting"
exit 1
fi

### Placing lock file
touch $LOCK_FILE

你要写的代码 

### Removing lock
rm -f $LOCK_FILE

Linux中如何防止一个Shell脚本被重复执行?

如何避免shell脚本被同时运行多次

Shell脚本避免重复执行的方法

防止同一个Java应用重复启动的shell脚本

shell脚本特殊符号

shell脚本中一些特殊符号

MySQL backup shell script

https://fedingo.com/shell-script-to-backup-mysql-database/

https://www.fosstechnix.com/shell-script-for-mysql-database-backup/

https://gist.github.com/lon-io/9067f746cd8cce10af4c52179c7e9b7e

https://orahow.com/linux-shell-script-for-mysql-database-backup/

shell规范

https://www.shellcheck.net/

Shell编程规范实践指南

Shell脚本书写规范

shell书写规范建议

shell脚本编写规范(超实用)

see also

Linux运维处理及监控脚本


CentOS下查看cpu,内存,硬盘等硬件信息的方法

linux系统中的shell脚本||脚本常用的命令

linux运维脚本开发工具,送给运维人员的8个编写脚本的建议 shell循环loop