-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecddcdb
commit 212f2a4
Showing
121 changed files
with
1,828 additions
and
1,849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
# 无法通过 sudo 重定向来修改特权文件,下面的命令执行会失败 | ||
# sudo echo 'DEV_SERVER=https://dev.shiyanlou.com' >> /etc/profile | ||
# 以 root 身份来运行 tee 命令,从而可以修改特权文件 | ||
echo 'DEV_SERVER=https://dev.shiyanlou.com' | sudo tee -a /etc/profile | ||
|
||
# 修改用户自己的文件不需要特权 | ||
echo 'DEV_ACCOUNT=shiyanlou' >> ~/.zshrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# 创建 test 组 | ||
sudo groupadd test | ||
|
||
# 创建 dev 组 | ||
sudo groupadd dev | ||
|
||
# 创建 jack 用户 | ||
sudo useradd -m -d /home/jack -s /bin/zsh -g shiyanlou -G dev jack | ||
|
||
# 创建 bob 用户 | ||
sudo useradd -m -d /home/bob -s /bin/bash -g shiyanlou -G test bob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# 进入 HOME 目录并创建 backup 子目录 | ||
cd ~ && mkdir backup | ||
|
||
# 查找 /etc 目录下大小超过 12k 的文件并拷贝到 backup 目录下,拷贝的时候需要保留路径信息,通过重定向将标准错误输出忽略掉 | ||
find /etc -type f -size +12k -exec cp --parents {} backup \; 2> /dev/null | ||
|
||
# 打包并压缩 backup 目录 | ||
tar -czf /tmp/backup.tar.gz backup |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# 进入 HOME 目录 | ||
cd ~ | ||
|
||
# 查找 /etc 目录下 .conf 结尾的文件列表,排序后保存到 conflist.txt | ||
find /etc -type f -name \*.conf 2> error.txt | sort > conflist.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# 进入 HOME 目录并创建 backup 子目录 | ||
cd ~ && mkdir backup | ||
|
||
# 将现有定时任务保存到 tasks 文件中 | ||
crontab -l > tasks | ||
# 往 tasks 文件里追加一个任务 | ||
echo '0 3 * * * cd ~/backup && sudo tar -g backinfo -czf $(date +%Y-%m-%d).tar.gz /var/log/ 2>> error.log' >> tasks | ||
# 使用 tasks 文件来重新配置定时任务 | ||
crontab tasks | ||
# 删除 tasks 文件 | ||
rm tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# 更新软件仓库信息 | ||
sudo apt-get update | ||
|
||
# 安装 sqlite3 和 postgresql,-y 选项表示无需确认直接安装 | ||
sudo apt-get install -y sqlite3 postgresql | ||
|
||
# 启动 postgresql 服务 | ||
sudo service postgresql start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# 安装 nginx 服务 | ||
sudo apt-get update && sudo apt-get install nginx | ||
|
||
# 启动 nginx 服务 | ||
sudo service nginx start | ||
|
||
# 查找 vnc 进程得到进程 ID | ||
# ps -ef | grep vnc | ||
# 使用 kill 命令发送信号给进程,默认发送 TERM 信号。如果进程不理会,可以发送 KILL 信号强制杀掉 | ||
# kill -KILL PID | ||
|
||
# 使用 pkill 发送信号给名称包含 vnc 的进程 | ||
pkill -KILL vnc |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# 定义配置文件和目标文件常量 | ||
CONFIG=files-to-backup.txt | ||
ARCHIVE=archive-$(date +%Y%m%d).tar.gz | ||
|
||
cd ~ | ||
|
||
# 检查配置文件是否存在 | ||
if ! [ -f $CONFIG ] | ||
then | ||
echo "$CONFIG does not exist." | ||
exit 1 | ||
fi | ||
|
||
# 重定向 while 命令的标准输入为 CONFIG 文件,依次读入每一个要备份的文件,检查其存在性,最终得到需要备份的文件列表 | ||
while read -r file | ||
do | ||
if [ -f $file -o -d $file ] | ||
then | ||
files="$files $file" | ||
else | ||
echo "$file does not exist, it will be skipped." | ||
fi | ||
done < "$CONFIG" | ||
|
||
# 备份文件 | ||
echo "Starting archive..." | ||
tar -czf $ARCHIVE $files | ||
echo "Archive completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# 第 1 个参数为服务名 | ||
service=$1 | ||
|
||
# 查询服务状态 | ||
sudo service "$service" status | ||
|
||
# service 命令的退出码具有特殊含义 | ||
status=$? | ||
case $status in | ||
0) | ||
echo "is Running" | ||
;; | ||
1) | ||
echo "Error: Service Not Found" | ||
;; | ||
3) | ||
echo "Restarting" | ||
sudo service "$service" start | ||
;; | ||
esac | ||
|
||
# 以 service 命令的退出码作为脚本退出码 | ||
exit $status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# 先备份现有定时任务到文件中,然后追加一个新任务到该文件,最后再使用该文件重新配置 crontab | ||
cd ~ | ||
crontab -l > tasks | ||
echo '* * * * * /home/shiyanlou/check_service.sh mysql' >> tasks | ||
crontab tasks | ||
rm tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sed -f | ||
|
||
# 替换所有 http 地址为 https | ||
s/http:\/\//https:\/\//g | ||
|
||
# 修正缺少 ! 的图片链接 | ||
s/^\[(.*)\]\((.+\.(png|jpg))\)/\!\[\1\]\(\2\)/g | ||
|
||
# 修正不需要 ! 的压缩包链接 | ||
s/\!\[(.*)\]\((.+\.tar\.gz)\)/\[\1\]\(\2\)/g | ||
|
||
# 有序列表的序号跟后续内容之间要有空格 | ||
s/^([0-9]+\.)(\S.+)$/\1 \2/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/awk -f | ||
|
||
# 打印列名 | ||
BEGIN { | ||
printf("%5s\t%-s\n", "COUNT", "USER") | ||
} | ||
|
||
# 跳过 ps 命令输出的第一行,然后按每行的第一列(用户名)来分组计数 | ||
NR>1 { | ||
num[$1]++ | ||
} | ||
|
||
# 最后打印每个用户的统计结果,并发送给 sort 命令排序后输出 | ||
END { | ||
for (i in num) { | ||
printf("%5d\t%-s\n", num[i], i) | "sort -r -n -k1" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.