Skip to content

Commit

Permalink
shell基础学习,shell结合cgi,shell结合php相关功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjianger committed Nov 29, 2017
1 parent 70c71f6 commit 89970d2
Show file tree
Hide file tree
Showing 73 changed files with 12,228 additions and 0 deletions.
2 changes: 2 additions & 0 deletions linux_basis/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ netstat -tunpl | grep 80

wc -l #统计条数

#递归显示文件
ls -lhR /usr/share/nginx/html/panda >> /var/log/pubdir.log



Expand Down
90 changes: 90 additions & 0 deletions shell_basis/shell_awk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
#test.sh

#awk
#-F 分割 print 输出
#cat /etc/passwd | awk -F: '{print $1"=>"$2"=>"$3}'
#cat /etc/passwd | head -5 | awk -F: '{print $1"=>"$2"=>"$3}'

#以冒号进行分割
#for i in `cat /etc/passwd | awk -F: '{print $1"=>"$2"=>"$3}'`; do
# echo $i
#done
#
## NR 行数 $0代表整行
#df | awk '{if(NR==3){print}}'
#
## int 将参数转换成整数
#df | awk '{if(NR==3){print int($4)}}'
#
##总共多少行
#df | awk 'END{print NR}'
#
##总共多少列
#df | awk 'END{print NF}'
#
##文件中第一列 匹配192.168.1.1的行数 输出第一列
#cat file | awk '$1~/192.168.1.1/{print $1}'
#
##文件中第一列 不匹配192.168.1.1的行数 输出第一列
#cat file | awk '$1!~/192.168.1.1/{print $1}'

#sed 行定位的使用

# 输出包含bash的数据
#cat file | sed -n '/bash/'p
#
## 输出包含bash到最后的数据
#cat file | sed -n '/bash/,$'p
#
#df | sed -n '3'p| awk '{print $2}'

#uniq -c file 打印紧挨着的重复
#uniq -d file 打印重复行
#uniq file 去重

#wc -l file 打印行数


#sort 排序
#cat file | sort | uniq -c
#
##倒叙
#cat file | sort -r | uniq -c
#
##根据第二列进行排序 sort -t: -k2 -r //以冒号分割
#cat file | sort -k2 -r

#split 行分割 按5行分割文件 sptab sptac
#split -5 file spt

#/var/log/nginx/log/host.access.log
#cat /var/log/nginx/log/host.access.log | sort -k1 | uniq -c
#cat /var/log/nginx/log/host.access.log | awk '{print $1}' | sort | uniq -c //1秒内 同一个ip访问次数



























17 changes: 17 additions & 0 deletions shell_basis/shell_char.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#shell_char.sh

#字符串比较
read -p "please your name: " name
read -p "please your age: " age
echo $name

## 字符串比较 = 不等于是!= 字符串是 -z
if [ $name = 'admin' ];then
echo "欢迎登陆"
fi

#数字比较用 -eq -gt -lt
if [ $age -gt 10 ];then
echo "成年了"
fi
100 changes: 100 additions & 0 deletions shell_basis/shell_chkconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
#test.sh

##linux 启动流程
#
##查看sshd在所有级别下的开启和关闭状态
#chkconfig --list sshd
#
##sshd 服务在35级别下开启
#chkconfig --level 3 sshd on
#
##sshd 服务在35级别下关闭
#chkconfig --level 3 sshd off
#
##快速设置sshd 服务 在2345级别开启
#chkconfig sshd on
#
##快速设置sshd 服务 在2345级别关闭
#chkconfig sshd off

#实例: 安装apache应用程序,然后让apache服务在3级别启动
#rpm -qa | grep httpd 查看rpm安装的包
#rpm -e httpd* 卸载rpm安装的包
#pstree | grep httpd 查看某个进程是否启动

#查看摸个级别可启动的服务
#cd /etc/rc.d/rc3.d/

#查看当前运行级别 runlevel

#rpm包软件
#服务脚本 /etc/rc.d/init.d/httpd

#源代码软件
#服务脚本 /usr/local/apache2/bin/apachectl
#开启 /usr/local/apache2/bin/apachectl start|stop
#开机开启 vi /etc/rc.d/rc.local /usr/local/apache2/bin/apachectl start

# /etc/rc.d/rc.local

#源代码安装三步走
#生成配置文件 ./configure --prefix=/usr/local/apache
#编译 make
#安装 make install (安装到 --prefix 要求的目的地)

#自定义服务脚本
case $1 in
start)
echo "test start"
sleep 1
;;
stop)
echo "test stop"
sleep 1
;;
restart)
echo "test restart"
sleep 1
;;
*)
echo 'please input start|stop|restart ...'
;;
esac

#把服务脚本改成标准的rpm脚本


#通过service把自定义脚本进行开启和关闭
#将脚本拷贝到init.d 下面就可以 service test start 要能接收参数

#通过chkconfig把自定义脚本设置开机启动 需要加入.有两种方式。可以写到 vi /etc/rc.d/rc.local 中。 也可以chkconfig httpd on

# chkconfig: 2345 90 20
# description: test server daemon

/usr/share/nginx/html/panda/shell/test.sh start
























34 changes: 34 additions & 0 deletions shell_basis/shell_e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# -e输出语句里面的转义符 换行
#echo -e "ewewe\ndasdasd"
## -n 输出语句里面的转义符 不换行
#echo -n "请输入你的名字: "
#read name
#echo "欢迎您$name"

# 颜色
# \033[前景颜色;背景颜色m
# \033[0m 恢复系统颜色
#前景色 30黑色 31红色 32绿色 33棕色 34蓝色 35紫色 36青色 37白色
#背景色 40黑色 41红色 42绿色 43棕色 44蓝色 45紫色 46青色 47白色

time=`date '+%Y-%m-%d'`
echo -e "今天是\033[32;40m${time}\033[0m,天气很美好"

#./test.sh | tee menu.txt 有利于边输出边保存

#输出前10行并输出行号
#cat /etc/passwd|head|nl

#nl 输出行号
nl /etc/passwd

#文档原型输出
cat<<x
please input your name:
1)aaaaaaaaa
2)aaaaaaaaa
3)aaaaaaaaa
4)aaaaaaaaa
x
61 changes: 61 additions & 0 deletions shell_basis/shell_find.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#test.sh

#
#find ./ -name "*.txt"
#find ./ -name "*.doc"
#find ./ -name "[a-z]*.txt"
#find ./ -name "[a-z]*.txt"
#find ./ -name "file[1-5].txt"

#find /etc -name ifcfg-eth0

#查权限
#find ./ -perm 777 -type f

#查类型
#find ./ -type f 是目录
#find ./ -type d 是文件
#find ./ -type l 是链接

#查找root用户创建的文件
#find -user root

#5天以内修改的文件
#find /var -mtime -5
#5天以前修改的文件
#find /var -mtime +5

#stat /etc/passwd 查看文件相关信息

#大于1M的文件
#find ./ -size +1000000c
#小于1M的文件
#find ./ -size -1000000c

#xargs 将find找到的文件 经过后面的处理
#find | xargs rm -rf

#正则表达式






















11 changes: 11 additions & 0 deletions shell_basis/shell_for.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

for i in `ls /home`
do
echo $i
done

for (( i=0; i<10; i++ )); do
echo $i
sleep 0.2
done
14 changes: 14 additions & 0 deletions shell_basis/shell_func.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

#函数
function add(){
# $1 接收第一个参数 $2接收第二个参数
num=$1
tot=0
for ((i=0; i<=$num; i++)); do
tot=$(($tot+$1))
done
echo $(($tot + $2))
}
#传参
add 10 20
Loading

0 comments on commit 89970d2

Please sign in to comment.