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 ...
随机推荐
- excel跨表查询数据
环境:公司部分部门进行商品盘点,店铺经理要求不经过系统进行盘点,全程采用excel表格处理所示: 左图为总表,右图为首饰部门录入的数据 需求:找出盘点差异(即首饰部商品数量是否和 ...
- js 流程控制语句
1.复合语句 2.switch语句 3.do...while语句 4.while语句 5.for语句 6.for...in语句 7.break和continue语句 9.with语句 10.if语句 ...
- react组件生命周期过程
实例化 首次实例化 getDefaultProps getInitialState componentWillMount render componentDidMount 实例化完成后的更新 getI ...
- Vsftpd服务传输文件(转)
本章节先通过介绍文件传输协议来帮助读者理解FTP协议的用处,安装vsftpd服务程序并逐条分析服务文件的配置参数. 完整演示vsftpd服务匿名访问模式.本地用户模式及虚拟用户模式的配置方法,介绍PA ...
- Codeforces 760B Frodo and pillows
题目链接:http://codeforces.com/problemset/problem/760/B 题意:n个床位,m个枕头,第k个位置最多有多少个枕头,其中相邻之间的差<=1; 第k个位置 ...
- Poj(1426),BFS
题目链接:http://poj.org/problem?id=1426 可能数据比较水,没有用到大整数.刚刚开始的时候,想从后往前加0或者1,发现有点难写,后来想到先放一个1,再1*10,1*10+1 ...
- HDU(1754),线段树,单点替换,区间最值
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 线段树模板题,update功能是单点替换,query是访问区间最大值. #include < ...
- 前端面试题(来自前端网http://www.qdfuns.com/notes/23515/c9163ddd620baac5dd23141d41982bb8.html)
HTML&CSS 1. 常用那几种浏览器测试?有哪些内核(Layout Engine)? (Q1)浏览器:IE,Chrome,FireFox,Safari,Opera. (Q2)内核:Trid ...
- Python 初始—(装饰器)
本质上也是函数的另一种表现形式,为其它函数丰富其功能,装饰其他函数,附加功能 在不改变被装饰的函数的源代码,而且不改变被装饰的函数的调用方式,因此被装饰的函数感知不到装饰器函数的存在 分解装饰器 函数 ...
- yum 仓库配置
[base]name=aliyum basebaseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/ ...