shell参数 传递
$# 是传给脚本的参数个数$0 是脚本本身的名字$1 是传递给该shell脚本的第一个参数$2 是传递给该shell脚本的第二个参数$@ 是传给脚本的所有参数的列表$* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过9个$$ 是脚本运行的当前进程ID号$? 是显示最后命令的退出状态,0表示没有错误,其他表示有错误 |
区别:@*
- 相同点:都是引用所有参数
- 不同点:只有在双引号中体现出来。假设在脚本运行时写了三个参数(分别存储在12 3)则"*" 等价于 “12 3"(传递了一个参数);而“@" 等价于 "1""2" "$3"(传递了三个参数)
一个守护脚本 demon:
###################
# VERSION=0.0.
################### #!/bin/bash
###############################
####Global parameters##########
############################### set -x #echo on CUR_DIR=`pwd`
VA_LOG_LEVEL="err"
VA_RUN_LEVEL="demon" ####for record file delete
DEFAULT_DAYS=
RECORD_FILE_PATH=/var/video_record
DEFAULT_FILE_CHECK=
##### unit : G
DEFAULT_MINI_SPACE=
PROCESS_NUM=
#CertMS
#DarwinStreamingServer #CertMS_Server
#Darwin_Server #functions
###################
##parse argument
###################
usage()
{
echo "######################################" echo "usage of maintain.sh :"
echo "options "
echo "-l : videomon log level [warn , info , err] , default is err"
echo "-m : videomon run mod[demon , foreground] , default is demon"
echo "-c : record file delete check! [ 0:not check 1:check , default is 1]"
echo "-n : [Delete the record files of the n days ago , default is 15 days]"
echo "-d : [record file path , default is :/var/video_record]"
echo "For example: ./maintain.sh -l info -m foreground -c 1 -n 10 -d /video_record or ./maintain.sh "
echo "-? : usage info" echo "######################################"
} get_opt()
{
while getopts ":?l:m:c:n:d:" optname
do
case "$optname" in
"l")
VA_LOG_LEVEL=$OPTARG
;;
"m")
VA_RUN_LEVEL=$OPTARG
;;
"c")
DEFAULT_FILE_CHECK=$OPTARG
;;
"n")
DEFAULT_DAYS=$OPTARG
;;
"d")
RECORD_FILE_PATH=$OPTARG
;;
"?")
usage
exit
;;
*)
# Should not occur
echo "maintain.sh :Unknown error while processing options"
exit
;;
esac
done
} ####################
##Video_Monitor clean
####################
video_monitor_clean()
{
for (( i = ; $i < PROCESS_NUM; i++ ));
do
echo $i;
pid_videomon=`ps aux|grep -v grep|grep "videomon$i" | grep "$"|sed -n '1P'|awk '{print $2}'` if [ $pid_videomon ]
then
killall - videomon$i
fi
done
} ####################
##ran_videomon_monitor
####################
ran_videomon_monitor()
{
echo $
cd $CUR_DIR/bin$ if [ $VA_RUN_LEVEL == "demon" ]
then
nohup ./videomon$ -l $VA_LOG_LEVEL -p pid -d &
else
nohup ./videomon$ -l $VA_LOG_LEVEL -p pid &
fi echo Start videomon Success!
} ####################
##record file check
####################
record_file_check()
{
cd $CUR_DIR
if [ -f record_file_delete.sh ]
then
chmod +x record_file_delete.sh
###
pid_record_sh=`ps aux|grep -v grep|grep "record_file_delete.sh" | grep "$"|sed -n '1P'|awk '{print $2}'`
if [ -z $pid_record_sh ]
then
nohup ./record_file_delete.sh -n $DEFAULT_DAYS -d $RECORD_FILE_PATH -s $DEFAULT_MINI_SPACE &
else
echo "record_file_delete.sh is running!"
fi
###
else
echo "Can not find record_file_delete.sh"
return
fi
} ####################
##videomon_maintain
#################### videomon_maintain()
{
while true
do
sleep ####Check whether need to delete record files
if [ $DEFAULT_FILE_CHECK -eq ]
then
record_file_check
fi for (( i = ; $i < PROCESS_NUM; i++ ));
do
echo $i;
pid=`ps aux|grep -v grep|grep "videomon$i -l $VA_LOG_LEVEL" | grep "$"|sed -n '1P'|awk '{print $2}'`
if [ -z $pid ]
then
ran_videomon_monitor $i
fi
done
done
} ###############
##start process
###############
get_opt $@
if [ $? != ]
then
echo get_opt unknow options!
exit
fi video_monitor_clean for (( i = ; $i < PROCESS_NUM; i++ ));
do
ran_videomon_monitor $i
done videomon_maintain
参考http://www.cnblogs.com/kaituorensheng/p/4002697.html
shell参数 传递的更多相关文章
- Shell如何传递字符串
Shell 在写函数的时候,有时候需要传递字符串,由于字符串中有空格,所以结果总是不对,下面写个小例子,解决这个问题: #!/bin/bash # value init TT="adb sh ...
- shell 参数
转:http://hi.baidu.com/ipvsadm/item/489d9e16460195ddbe9042ee linux中shell变量$#,$@,$0,$1,$2的含义解释 linux中s ...
- shell 参数与逻辑结构语句
shell参数 如同ls 命令可以接受目录等作为它的参数一样,在shell编程时同样可以使用参数.Shell有位置参数和内部参数. 1. 位置参数 由系统提供的参数称为位置参数.位置参数的值可以用$N ...
- JAVA 数组作为方法参数—传递地址
package Code411;//数组作为方法参数—传递地址public class DodeArrayParam { public static void main(String[] args) ...
- shell如何传递变量到另一个脚本文件中
http://www.jbxue.com/article/shell/20707.html本文介绍了shell脚本传递变量到另一个脚本文件中的方法,在脚本中调用另一脚本,即创建了一个子进程,感兴趣的朋 ...
- Linux Shell参数替换
Linux Shell参数替换 2013-06-03 10:01 by 轩脉刃, 1816 阅读, 0 评论, 收藏, 编辑 Bash中的符号的作用是参数替换,将参数名替换为参数所代表的值.对于 来说 ...
- Django---路由系统,URLconf的配置,正则表达式的说明(位置参数),分组命名(捕获关键字参数),传递额外的参数给视图,命名url和url的反向解析,url名称空间
Django---路由系统,URLconf的配置,正则表达式的说明(位置参数),分组命名(捕获关键字参数),传递额外的参数给视图,命名url和url的反向解析,url名称空间 一丶URLconf配置 ...
- hive shell参数
Hive Shell参数 1.Hive命令行 语法结构 hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e ...
- shell如何传递外部参数给文件
shell里面如何传递参数: sh test.sh zhang 20 那test.sh里面咋接受参数呢? #!/usr/bin/env sh name=$1 age=$2 echo "nam ...
随机推荐
- centos7 gearmand-1.1.15打包rpm
wget https://github.com/gearman/gearmand/releases/download/1.1.15/gearmand-1.1.15.tar.gz -O /root/rp ...
- phpstorm 2017.1 激活
打开网址 http://idea.lanyus.com/ 选择获取注册码,复制生成的验证码 安装完成后,打开软件,依次选择菜单栏 Help -> Register-> Activation ...
- 笨办法学Python(四)
习题 4: 变量(variable)和命名 你已经学会了 print 和算术运算.下一步你要学的是“变量”.在编程中,变量只不过是用来指代某个东西的名字.程序员通过使用变量名可以让他们的程序读起来更像 ...
- 安装国际版firefox(火狐浏览器)并设置语言为中文
访问https://www.mozilla.org/zh-CN/firefox/new/?scene=2下载.安装: 访问https://addons.mozilla.org/zh-CN/firefo ...
- May 03rd 2017 Week 18th Wednesday
Truth needs no colour; beauty, no pencil. 真理不需要色彩,美丽不需要涂饰. There is no absoulte truth and everlastin ...
- java集合框架——List
一.List接口概述 List有个很大的特点就是可以操作角标. 下面开始介绍List接口中相对于Collection接口比较特别的方法.在Collection接口中已经介绍的方法此处就不再赘述. 1. ...
- 94. Binary Tree Inorder Traversal(inorder ) ***(to be continue)easy
Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...
- Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.错误
错误如图示: 1.在php的目录下建立个文件夹tmp,这个有权限的问题,如果是ntfs的分区,就一定要添加evryone的控制权限,否则是没用的.2.在php.ini找到session.save_pa ...
- java 通过接口在后台管理器中生成数据
需求:测试人员在后台批量添加数据很麻烦,特别是针对一款商品配置了英语,还需要手动添加法语.俄语.阿拉伯语,很麻烦,但是因为没有项目组配合,做个小工具批量生成数据就只有自己去研究了 第一步:通过抓包工具 ...
- HttpContext.RewritePath
定义:使用给定路径重写 URL.就是可以跳转到指定的URL. 也可以做为伪静态的跳转.具体如下. 他的重载 ①新建一个页面,放两个链接到另一个页面,注意给的链接 ②在 global.asax 文件中 ...