时间:2024-04-26 18:19:41 来源: 人气:
Linux 环境下的 hosts 一键部署脚本,由 @lstoars 贡献; @fluviusmagnus 提供增强版本。
官方网站:https://github.com/racaljk/hosts/tree/master/hosts_tools
#!/bin/sh # # script_tool_for_linux # # Use command: `sudo sh script_tool_for_linux.sh` or # `su -c 'sh script_tool_for_linux.sh'` # to update your hosts file. # # WARNING: the script CAN NOT replace others' hosts rules. # If you have hosts rules provided by others, you may get conflict. # if [ `id -u` -eq 0 ]; then curl -fLo /tmp/fetchedhosts 'https://raw.githubusercontent.com/racaljk/hosts/master/hosts' sed -i '/# Copyright (c) 2014/,/# Modified hosts end/d' /etc/hosts sed -i "s/localhost/`hostname`/g" /tmp/fetchedhosts cat /tmp/fetchedhosts >> /etc/hosts rm -f /tmp/fetchedhosts echo 'Success.' else echo 'Permission denied, are you root?' fi
Shell脚本的条件控制和循环语句
条件判断:if语句语法格式:if[expression]thenStatement(s)tobeexecutedifexpressionistruefi注意:expression和方括号([])之间必须有空格,否则会有语法错误。if语句通过
实战模拟监控MySQL服务shell脚本小结
1)端口判断法==仅适合数据库本地使用法1:if条件判断方法[root@oldboyscripts]#catcheck_db01.sh#!/bin/sh#createdbyoldboy#mail:oldboy521@gmail.comPortNum=`netstat-lnt|grep3306|wc-l`
一天一个shell命令 文本操作系列-linux dd使用教程
今天第一天写,先说下写shell脚本的基本知识1.shell脚本以.sh为扩展名,通常运行./${filename}.sh或者sh${filename}.sh2.shell脚本开头以#!/bin/bash#!读作shebang3.开启