Linux shell 函数应用示例02
nginx服务控制脚本:
安装ngix
[root@wei function]# yum install gcc pcre-devel openssl-devel
[root@wei function]# tar xf nginx-1.14.2.tar.gz
[root@wei function]# cd nginx-1.14.2
[root@wei nginx-1.14.2]# ./configure --prefix=/usr/local/nginx
[root@wei nginx-1.14.2]# make && make instal
编写控制nginx的脚本
#!/bin/bash
#
nginx_cmd=/usr/local/nginx/sbin/nginx
nginx_conf=/usr/local/nginx/conf/nginx.conf
nginx_pid_file=/usr/local/nginx/logs/nginx.pid
start(){
$nginx_cmd
if [ $? -eq 0 ];then
echo "服务nginx启动.....[ok]"
fi
}
stop(){
$nginx_cmd -s stop
}
reload(){
if $nginx_cmd -t &> /dev/null;then
$nginx_cmd -s reload
else
$nginx_cmd -t
fi
}
status(){
if [ -e $nginx_pid_file ];then
echo "服务nginx(`cat $nginx_pid_file`) is running"
else
echo "服务nginx is stopped"
fi
}
if [ -z $1 ];then
echo "使用:$0{start|stop|restart|reload|status}"
exit 9
fi
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
reload)
reload
;;
*)
echo "使用:$0{start|stop|restart|reload|status}"
exit 9
;;
esac
演示:
[root@wei init.d]# /etc/init.d/nginx status
服务nginx(4974) is running
[root@wei init.d]# /etc/init.d/nginx statscdsdc
使用:/etc/init.d/nginx{start|stop|restart|reload|status}
[root@wei init.d]# /etc/init.d/nginx stop
[root@wei init.d]# /etc/init.d/nginx status
服务nginx is stopped
[root@wei init.d]# /etc/init.d/nginx start
服务nginx启动.....[ok]
Linux shell 函数应用示例02的更多相关文章
- Linux shell 函数应用示例01
函数Function的使用 定义函数 (1) 函数名称() { ... ... } (2) function 函数名称{ ... ... } 调用函数 ...
- Linux Shell函数返回值
转:http://blog.csdn.net/ithomer/article/details/7954577 Shell函数返回值,一般有3种方式:return,argv,echo 1) return ...
- Linux Shell 函数返回值
Shell函数返回值,常用的两种方式:return,echo 1) return 语句 shell函数的返回值,可以和其他语言的返回值一样,通过return语句返回. 示例: #!/bin/sh fu ...
- Linux Shell函数定义与调用
一.Shell函数定义格式 shell函数定义格式,各部分说明如下: [ function ]等中括号括起来部分----表示可选(即可有可无) your_function_name部分----为函数名 ...
- linux shell 函数返回值问题(超过255)
最近再写一个shell测试的时候出现问题,函数返回值异常 用shell计算斐波那契数列数列,写了一个shell函数,然后调用的,验证的时候我只随便计算了几个数(10以内),确认结果是正确的就提交了,后 ...
- Linux Shell函数
200 ? "200px" : this.width)!important;} --> 介绍 正文 $? $?是shell变量,表示"最后一次执行命令"的 ...
- Linux Shell——函数的使用
文/一介书生,一枚码农. scripts are for lazy people. 函数是存在内存里的一组代码的命名的元素.函数创建于脚本运行环境之中,并且可以执行. 函数的语法结构为: functi ...
- linux shell自定义函数(定义、返回值、变量作用域)介绍
http://www.jb51.net/article/33899.htm linux shell自定义函数(定义.返回值.变量作用域)介绍 linux shell 可以用户定义函数,然后在shell ...
- 转 linux shell自定义函数(定义、返回值、变量作用域)介绍
linux shell 可以用户定义函数,然后在shell脚本中可以随便调用.下面说说它的定义方法,以及调用需要注意那些事项. 一.定义shell函数(define function) 语法: [ f ...
随机推荐
- 「总结」插头$dp$
集中做完了插头$dp$ 写一下题解. 一开始学的时候还是挺蒙的. 不过后来站在轮廓线$dp$的角度上来看就简单多了. 其实就是一种联通性$dp$,只不过情况比较多而已了. 本来转移方式有两种.逐行和逐 ...
- [LeetCode] 296. Best Meeting Point 最佳开会地点
A group of two or more people wants to meet and minimize the total travel distance. You are given a ...
- python实现的WebSocket客户端
code #coding=utf- import json import time from websocket import create_connection ws = create_connec ...
- Spring Boot下Bean定义方式及调用方式
我们知道如果我们要在一个类使用spring提供的bean对象,我们需要把这个类注入到spring容器中,交给spring容器进行管理,但是在实际当中,我们往往会碰到在一个普通的Java类中,想直接使用 ...
- 责任链模式Scala的7种实现
责任链模式是经典的GoF 23种设计模式之一,也许你已经了解这种模式.不管你是否熟悉,建议读者在阅读本文之前,不妨先思考下面三个问题: (1) 如何用多种风格迥异的编程范式来实现责任链模式? (2) ...
- 为什么我的resharper控件安装之后没有显示
Resharper和Resharper C++有时候会出现,安装之后不显示,VisualStudio菜单栏内找不到的情况,大多数是因为启动VisualStudio的时候没有激活Resharper. 安 ...
- PHP的小技巧
PHP的小技巧fdd()[0]函数后面可以直接加数组索引 这样可以省内存占用啦 代码也更简洁
- [转帖]【译】RAID的概念和RAID对于SQL性能的影响
[译]RAID的概念和RAID对于SQL性能的影响 https://www.cnblogs.com/VicLiu/p/11479427.html 简介 我们都听说过RAID,也经常作为SQL DBA. ...
- 第八节:EF Core连接MySql数据库
一. 前提 1.安装EF Core连接MySQL的驱动,这里有两类: (1).Oracle官方出品:MySql.Data.EntityFrameworkCore (版本:8.0.17) (2).其他第 ...
- WPF Properties中Settings使用方式
Settings位于Properties中 代码上看Setting是一个单例模式 其中可以编写属性,方法 因为Setting位于窗口类之前实例化,所以通常用来窗口的某些设置,绑定. --------- ...