上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页
摘要: 编写shell脚本难免遇到需要交互式输入指令的步骤: 方法一: # cat action.sh #!/bin/sh read -p "enter number:" no; read -p "enter number:" name; echo you have entered $no,$name; # 阅读全文
posted @ 2017-06-19 23:25 ChavinKing 阅读(1340) 评论(0) 推荐(0)
摘要: sort命令可以帮助我们对文本文件或stdin输入进行排序,sort通常配合其他命令进行输出操作。uniq是一个经常与sort使用的命令。作用是从文本或stdin读取唯一的行,uniq要求输入必须经过排序。 按数字顺序排序: # sort -n dept 10 ACCOUNTING NEW YORK 阅读全文
posted @ 2017-06-19 22:21 ChavinKing 阅读(294) 评论(0) 推荐(0)
摘要: tr命令用来进行对标准输入的内容做替换。例如 # echo 'HELLO WORLD!!!' | tr "A-Z" "a-z" hello world!!! 这里的"A-Z"、"a-z"都表示集合,shell脚本中定义集合类型很简单,即指定集合序列即可,但是对于上边的情形,不得非输入所有集合类型,可 阅读全文
posted @ 2017-06-19 17:48 ChavinKing 阅读(1227) 评论(0) 推荐(0)
摘要: 首先看一下文本信息: # cat text1.txt 1 2 3 4 5 使用xargs格式化一下: # cat text1.txt | xargs 1 2 3 4 5 使用xargs格式化,每两个单词一组: # cat text1.txt | xargs | xargs -n 2 1 2 3 4 阅读全文
posted @ 2017-06-19 11:31 ChavinKing 阅读(2254) 评论(0) 推荐(0)
摘要: find列出目录下所有文件: # find /shell-script/ # find /shell-script/ -print find列出文件夹中所有开头为text的文件,参数-iname意思忽略大小写: # find /shell-script/ -name "text*"# find /s 阅读全文
posted @ 2017-06-18 22:31 ChavinKing 阅读(237) 评论(0) 推荐(0)
摘要: 一、分支控制语句 1、if .. fi条件 if condition; then action fi 2、if .. else .. fi条件 if condition;then action; else action fi 3、if .. else if ..else ..fi条件 if cond 阅读全文
posted @ 2017-06-18 18:07 ChavinKing 阅读(658) 评论(0) 推荐(0)
摘要: 方法: kill –9 `pgrep java` 使用上述命令可以将服务器上运行的所有java进程一次性kill掉。 扩展:子shell和反应用在shell脚本中的作用 先来看一个子shell的例子: # cat text1.txt 1 2 3 4 5 # text01=$(cat text1.tx 阅读全文
posted @ 2017-06-18 16:48 ChavinKing 阅读(457) 评论(0) 推荐(0)
摘要: 测试脚本如下,我这里主要想测试$0,$1,$2,$n,$@,$*默认都代表了什么? #!/bin/sh echo '$1='$1 echo '$2='$2 echo '$@='$@ echo '$*='$* echo '$0='$0 测试: # sh var.sh 1 2 $1=1 $2=2 $@= 阅读全文
posted @ 2017-06-18 16:21 ChavinKing 阅读(184) 评论(0) 推荐(0)
摘要: #!/bin/sh echo -n radio: tput sc #保存当前光标位置 count=0 while true; do if [ $count -lt 10 ];then let count++; sleep 1; #休眠1秒 tput rc; #取出当前光标位置 tput ed #ra 阅读全文
posted @ 2017-06-18 16:04 ChavinKing 阅读(487) 评论(0) 推荐(0)
摘要: stty命令是一个终端处理工具。我们可以通过它来实现静默方式输入密码,脚本如下 #!/bin/sh echo –e “enter password:” stty –echo #禁止将输出发送到终端 read password #交互式读取 stty echo #允许将输出发送到终端 echo pas 阅读全文
posted @ 2017-06-18 15:23 ChavinKing 阅读(1474) 评论(0) 推荐(0)
摘要: 脚本内容如下: #!/bin/sh #定义变量 secs=3600unit_time=60 stepts=$(( $secs / $unit_time )) echo CPU usage...; for((i=0;i<stepts;i++))do ps -eo comm,pcpu | tail -n 阅读全文
posted @ 2017-06-17 10:59 ChavinKing 阅读(1249) 评论(0) 推荐(0)
摘要: 试验文件: [root@db03 shell-script]# cat text1.txt 1 2 3 4 5 [root@db03 shell-script]# cat text2.txt oracle mysql postgresql hadoop spark 使用paste拼接text1.tx 阅读全文
posted @ 2017-06-16 21:45 ChavinKing 阅读(4172) 评论(0) 推荐(0)
摘要: 测试文本内容如下: # cat textfile hadoop hdfs yarn spark zookeeper mapreduce hive hbase scala kafka CHAVIN mysql PostgreSQL mongodb 192.168.100.231 192.168.100 阅读全文
posted @ 2017-06-16 16:31 ChavinKing 阅读(1950) 评论(0) 推荐(0)
摘要: 我们知道可以通过工具grep或egrep按行筛选记录,这里我们可以通过cut工具对文本按列进行切分,它可以指定定界符,linux下制表符是默认的定界符。 #cut -f 2,3 textfile 这个命令可以显示textfile文件的第2、3列。 例如:有文件如下: # cat dept 10 AC 阅读全文
posted @ 2017-06-16 16:09 ChavinKing 阅读(3695) 评论(0) 推荐(0)
摘要: find /dbfdumpdir/*full* -mtime +21 -exec rm -rf {} \; 这个shell可以删除目录/dbfdumpdir下面21天前生成的,文件名包含full的文件。其实这个指令是我用来自动删除oracle 测试库中数据泵历史备份文件的脚本。 阅读全文
posted @ 2017-06-16 13:54 ChavinKing 阅读(472) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页