Skip to content

Commit

Permalink
replace master with 5th-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggerwang committed Oct 22, 2018
1 parent ecddcdb commit 212f2a4
Show file tree
Hide file tree
Showing 121 changed files with 1,828 additions and 1,849 deletions.
9 changes: 9 additions & 0 deletions 01/challenges/01/challenge.sh
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
6 changes: 6 additions & 0 deletions 01/challenges/05/create.sh → 01/challenges/02/challenge.sh
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
10 changes: 10 additions & 0 deletions 01/challenges/03/challenge.sh
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
5 changes: 0 additions & 5 deletions 01/challenges/03/ex.sh

This file was deleted.

5 changes: 0 additions & 5 deletions 01/challenges/03/sed.sh

This file was deleted.

5 changes: 0 additions & 5 deletions 01/challenges/03/tee.sh

This file was deleted.

7 changes: 7 additions & 0 deletions 01/challenges/04/challenge.sh
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
13 changes: 13 additions & 0 deletions 01/challenges/05/challenge.sh
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
10 changes: 10 additions & 0 deletions 01/challenges/06/challenge.sh
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
15 changes: 15 additions & 0 deletions 01/challenges/07/challenge.sh
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
7 changes: 0 additions & 7 deletions 01/challenges/08/find_and_tar.sh

This file was deleted.

4 changes: 0 additions & 4 deletions 01/challenges/11/find_and_output.sh

This file was deleted.

8 changes: 0 additions & 8 deletions 01/challenges/15/backup.sh

This file was deleted.

5 changes: 0 additions & 5 deletions 01/challenges/17/install.sh

This file was deleted.

8 changes: 0 additions & 8 deletions 01/challenges/20/manage.sh

This file was deleted.

30 changes: 30 additions & 0 deletions 02/challenges/01/daily_archive.sh
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"
25 changes: 25 additions & 0 deletions 02/challenges/02/check_service.sh
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
8 changes: 8 additions & 0 deletions 02/challenges/02/cron_install.sh
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash

# 检查参数是否为数字
function checkNumber() {
re='^[0-9]+([.][0-9]+)?$'
re='^[0-9]+(\.[0-9]+)?$'
if ! [[ $1 =~ $re ]]; then
return 1
fi
return 0
}

# 转换数字为最合适的显示单位
function Convert() {

if ! checkNumber $1; then
echo "expect number but receive $1"
return 1
Expand All @@ -30,4 +31,5 @@ function Convert() {
fi
}

# 调用 Convert 函数,直接传递所有脚本参数给函数
Convert $*
35 changes: 0 additions & 35 deletions 02/challenges/04/daily_archive.sh

This file was deleted.

13 changes: 13 additions & 0 deletions 02/challenges/04/fix_format.sed
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/
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Sed 文本编辑

## 介绍
本次挑战内容是...

本次挑战内容是...

## 目标

Expand All @@ -14,7 +16,6 @@
[资源数据1](https://www.shiyanlou.com/test1.tar.gz)
![资源数据2](https://www.shiyanlou.com/test2.tar.gz)


## 提示语

1.首先执行...
Expand Down
18 changes: 18 additions & 0 deletions 02/challenges/05/count_process.awk
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"
}
}
20 changes: 0 additions & 20 deletions 02/challenges/06/check_service.sh

This file was deleted.

10 changes: 0 additions & 10 deletions 02/challenges/06/cron_install.sh

This file was deleted.

8 changes: 0 additions & 8 deletions 02/challenges/11/fix_format.sed

This file was deleted.

15 changes: 0 additions & 15 deletions 02/challenges/14/count_process.awk

This file was deleted.

Loading

0 comments on commit 212f2a4

Please sign in to comment.