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 ...
随机推荐
- Linux网络基础设置
1.笔记 systenctl restart network:重启网卡网络服务 bash:刷新主机名称 netstat:查看网络状态 route -n:不做地址解析 mii-tool eno16777 ...
- 测开面试 | Python常问算法
1.排序 从小到大排序:sorted(list) 从大到小排序:sorted(list, reverse=True) sort() 方法,改变原有数组的顺序 sort(reverse=True) #! ...
- [LeetCode] 684. Redundant Connection 冗余的连接
In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...
- android 完全退出实现
实现方法是在application中定义一个集合存储所有的Activity对象,在Activity创建时添加进集合中,在程序退出时,finish掉所有的Activity即可. 步骤如下: 1.自定义A ...
- 关于交叉编译Nodejs的坑
前言 交叉编译Nodejs到其他平台上的时候,遇到了2个坑,网上极少有人提及,花了整个晚上才解决,在此记录下. 我的编译目标环境为: 龙芯3A 编译脚本 cd 代码目录 export PREFIX=/ ...
- idea创建maven多模块Spring Boot项目
1, 创建父项目 1.1,file - new - project 1.2,选择maven,Create from archetype(有的说不选,有的没说,不过我建父项目的时候没有勾选) 1.3,根 ...
- iphone 移动端操作记录
iPhone和Safari浏览器的后退按钮操作,是直接载入缓存中的页面,不会加载js文件,不会执行ready,onload函数,但是加载html页面会跑pageshow事件,因此有回退动作需要重新加载 ...
- gulp的初阶使用方法(转)
安装好gulp之后接下来就是使用了,此文主要介绍一些前端开发时常用的一些插件及其用法 http://www.imooc.com/article/tag/26/hot/12插件安装 安装本地服务器插件: ...
- APP 链接ROS时出现pymongo.errors.ServerSelectionTimeoutError: localhost:27017 错误
ROS版本上kinetic ,APP是官网开源的make a map,当app链接ROS进行建图时,会出现报错:pymongo.errors.ServerSelectionTimeoutError: ...
- vue中js文件中export常见方法及使用
js文件一般放静态资源或动态资源,我将在这两种不同资源的请求下以不同的方式export出来 第一种在js中使用function 动态资源 在vue文件中引用调用这些方法 import进来 在生命周期函 ...