随笔分类 - 002-Shell
摘要:一、#Set the right GC options based on the what we are runningdeclare -a server_cmds=("master" "regionserver" "thrift" "thrift2" "rest" "avro" "zookeepe...
阅读全文
摘要:一、shell中的":"实际案例:hbase脚本中一段===># For releases, add hbase & webapps to CLASSPATH# Webapps must come first else it messes up Jettyif [ -d "$HBASE_HOME/h...
阅读全文
摘要:日志回滚案例======>[root@localhost test]# cat hbase.sh hbase_rotate_log () { log=$1; num=5; if [ -n "$2" ]; then num=$2 fi if [ -f "$log" ]; then # rotate l...
阅读全文
摘要:1. 背景 在终端Vim中粘贴代码时,发现插入的代码会有多余的缩进,而且会逐行累加。原因是终端把粘贴的文本存入键盘缓存(Keyboard Buffer)中,Vim则把这些内容作为用户的键盘输入来处理。导致在遇到换行符的时候,如果Vim开启了自动缩进,就会默认的把上一行缩进插入到下一行的开头,最终使...
阅读全文
摘要:在shell提示符号下输入type killproc,会发现killproc实在 /sbin/目录下,通过man killproc可以查看这个脚本(姑且这么称为脚本)的用法,现在,把这个脚本的实现过程通过脚本实现了,请看下面脚本。#!/bin/bash## This script kills all...
阅读全文
摘要:d211 admin # for i in {3..254} ; do ping -c 1 192.168.1.$i &>/dev/null && echo 192.168.1.$i is alive ;done192.168.1.5 is alive192.168.1.7 is alivefpin...
阅读全文
摘要:vim /sbin/service#!/bin/sh. /etc/init.d/functions #读取环境变量.VERSION="$(basename $0) ver. 0.91" #"service[获取的第一个参数] ver. 0.91"对应后面的"service -V"USAGE="Us...
阅读全文
摘要:ip="192.168.5.166"ssh $ip -o StrictHostKeyChecking=no //ssh登陆不用输入"yes"port="26092"pid=`netstat -anlp|grep $port|awk '{print $7}'|awk -F"/" '{prin...
阅读全文
摘要:>&2 即 1>&2 也就是把结果输出到和标准错误一样;之前如果有定义标准错误重定向到某log文件,那么标准输出也重定向到这个log文件如:ls 2>a1 >&2 (等同 ls >a1 2>&1)把标准输出和标准错误都重定向到a1,终端上看不到任何信息。第一种情况:标准正确输出(有>&2)====》...
阅读全文
摘要:创建以当前时间为文件名的mkdir `date+%Y%m%d`备份以时间做为文件名的tar cvf./htdocs`date +%Y%m%d`.tar ./*date命令如何获得上星期的日期?lastmonth=`date+%Y-%m --date="-1 month"`"-01";然后 awk -...
阅读全文
摘要:Linux Shell 脚本中字符串的连接方法[root@localhost company]# var1=/etc/[root@localhost company]# var3=${var1}'yum.repos.d/'[root@localhost company]# echo $var3/et...
阅读全文
摘要:写在前面:案例、常用、归类、解释说明。(By Jim)使用函数#!/bin/bash# testing the scriptfunction myfun { echo "This is an example of a function"}count=1while [ $count -le 5 ]d...
阅读全文
摘要:用途说明 exit命令用于退出当前shell,在shell脚本中可以终止当前脚本执行。 常用参数 格式:exit n 退出。设置退出码为n。(Cause the shell to exit with a status of n.) 格式:exit 退出。退出码不变,即为最后一个命令的退出码。(If
阅读全文