运行后台任务
nohup ~/bin/xxx.sh &
运行 SpringBoot 的jar包:
nohup java -jar http_request_tool-0.0.1-SNAPSHOT.jar &
命令格式: nohup <命令> &
定时器
编辑定时器:
crontab -e
范例:
*/20 * * * * /Users/whuanghkl/study/cron/todo.sh
每20分钟执行一次
20 7 * * * /home/whuang/software/auto_start_tomcat.sh
每天的上午7点20分执行脚本
30 18 * * * /home/whuang/software/auto_innerSign.sh
每天的下午6点
每月末执行, 00 23 28-31 * * [ date -d tomorrow +%e
-eq 1 ] && /bin/bash youshell.sh
获取命令行参数
if [ x"$1" == x"i" ];then
echo "ignore io0007-0.0.1-SNAPSHOT.jar"
else
cd /Users/whuanghkl/code/mygit/io0007
mvn install
result2=$?
echo $result2
if [ $result2 -ne 0 ];then
echo "error."
exit 4
fi
fi
|格式|含义|
|$1|命令行的第一个参数| |$2|命令行的第二个参数|
创建用户
1,创建用户组
groupadd whuang
2,创建用户
useradd whuang -g whuang
-g 指定用户组
3,设置用户密码
passwd whuang
判断文件是否存在
test -f 判断是否存在
test -f ~/.bash_profile && source ~/.bash_profile
防止别人攻击
查看攻击的ip
linux命令:
grep "authentication failure" /var/log/secure
防止别人尝试登录
/etc/hosts.deny 编辑vim /etc/hosts.deny ,添加: sshd:115.28.240. sshd:89.163.134. sshd:109.74.248. sshd:104.197.46. sshd:43.241.208. sshd:121.42.177. sshd:121.41.108. sshd:112.74.68. sshd:43.250.44. sshd:207.190.196. sshd:121.41.121. sshd:1.82.243. sshd:73.186.113. sshd:138.118.7. sshd:107.184.57. sshd:120.26.106. sshd:123.56.4. sshd:112.74.113. sshd:89.34.24.
搜索文本文件
grep -rn "keyword" --exclude-dir "node_modules" ./
ROLE_SPECIFY是要搜索的关键字
重要参数说明:
--colour:指定搜索的关键字的颜色,取值范围:never',
always' or `auto'
--exclude-dir:要排除在外的目录名称,
Note that
-- exclude-dir patterns take priority over --include-dir patterns
-i, --ignore-case:忽略大小写;
-n, --line-number:显示行号 ;
-R, -r, --recursive:递归搜索目录及子目录;
-v, --invert-match:反转,所有不匹配的行;
-w, --word-regexp:作为整个单词来搜索
-E:使用正则表达式:例如:
tail -f ../../logs/catalina.out|grep -E "sameFileName|isEscapestr"
注意:必须是大写的E