Shell Step by Step (4) —— Cron & Echo
来源:互联网 发布:unity3d 支持的模型 编辑:程序博客网 时间:2024/06/06 01:41
6.脚本定时任务
# Example of job definition:# .------------------------- minute (0 - 59)# | .--------------------- hour (0 - 23)# | | .----------------- day of month (1 - 31)# | | | .------------- month (1 - 12) # | | | | .--------- day of week (0 - 6) # | | | | |# * * * * * user-name command to be executed
7.查看当前用户的UID
root@kallen:/usr/data/kallendb_backup# ps -ef | grep UID UID PID PPID C STIME TTY TIME CMD root 2872 2384 0 09:43 pts/2 00:00:00 grep --color=auto UID
8.用Shell模拟一个进度条
#! /bin/bash # # Progress Bar # Print # to view the process bar # create variable b='' # for loop for ((i=0;$i<=100;i+=2)) do printf "Progress:[%-50s]%d%%\r" $b $i sleep 0.1 b=#$b done echo
在Shell脚本的编写应用中,有时候会需要用到图形界面的案例,比如默认cp拷贝文件为静默模式,无法看到拷贝的进度与百分比。而dialog正是为Shell提供图形界面的工具,该工具可以为Shell脚本提供各式各样的图形界面,今天为大家介绍的是dialog提供的进度条图形功能。
dialog指令可以单独执行,格式为
dialog --title "Copy" --gauge "files" 6 70 10
备注:
title表示图形进度条的标题,
gauge为正文内容,进度条高度为6,宽度70,显示进度为10%
for i in {1..100} ; do sleep 1; echo $i | dialog --title 'Copy' --gauge 'I am busy!' 10 70 0; done
下面案例中通过统计源文件个数,再据此计算出拷贝文件的百分比,在Shell中提供进度的显示。
该脚本有两个参数,第一个参数为源文件路径,第二个参数为目标路径。
如果您的应用案例不同可以据此稍作修改即可使用。
#!/bin/bash # Description: A shell script to copy parameter1 to # parameter2 and Display a progress bar # Author:Jacob # Version:0.1 beta # Read the parameter for copy,$1 is source dir # and $2 is destination dir. dir=$1/* des=$2 # Test the destination dirctory whether exists [ -d $des ] && echo "Dir Exist" && exit 1 # Create the destination dirctory mkdir $des # Set counter, it will auto increase to the number of # source file. i=0 # Count the number of source file n=`echo $1/* |wc -w` for file in `echo $dir` do # Calculate progress percent=$((100*(++i)/n)) cat <<EOF XXX $percent Copying file $file ... XXX EOF /bin/cp -r $file $des &>/dev/nulldone | dialog --title "Copy" --gauge "files" 6 70 clear
效果如图:
9.Echo输出
功能说明: 显示文字
语 法:
echo [ -ne ] [ 字符串 ] 或 echo [ --help ] [--version ]
参数:
-n 不要在最后自动换行-e 若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出; \b 删除前一个字符; \f 换行但光标仍旧停留在原来的位置; \r 光标移至行首,但不换行; \t 插入tab; \v 与\f相同; \nnn 插入nnn(八进制)所代表的ASCII字符;--help 显示帮助--version 显示版本信息
热门推荐
LNMP环境搭建——Nginx篇
在RHEL6.5中配置本地YUM源
Ubuntu下Zabbix安装及使用问题
MySQL双主热备问题处理
0 0
- Shell Step by Step (4) —— Cron & Echo
- Shell Step by Step (1) —— Introduction
- Shell Step by Step (2) —— Variable
- Shell Step by Step (3) —— Stdin & if
- Step by step——WinX开发入门教程-4
- 深入MySQL源码—Step By Step
- step by step熟悉hbase shell
- 【opengl】【step by step】一————三角形
- NBearV3 Step by Step教程——IoC进阶篇
- NBearV3 Step by Step教程——IoC篇
- NBearV3 Step by Step教程——ORM进阶篇
- NBearV3 Step by Step教程——ORM篇
- Step by step——步步为营,学习嵌入式wince驱动
- Step by step——WinX开发入门教程-1
- Step by step——WinX开发入门教程-2
- Step by step——WinX开发入门教程-3
- Step by step——WinX开发入门教程-5
- Step by step——WinX开发入门教程-6
- GRE5-7个月考试复习时间安排
- 使用广泛的pdf分割软件
- Struts1和Struts2的区别和对比(完整版)
- 启动Tomcat时的常见问题及解决办法
- libssh2进行远程执行LINUX命令
- Shell Step by Step (4) —— Cron & Echo
- java基础整理のIO流
- SQL Server存储过程数组参数
- My97DatePicker:开始时间和结束时间的最大间隔为10天,并且不大于当前时间
- opencv在一个图片中显示任何你想表达的内容
- Android自定义控件——带阴影的ImageView(ShaderImageView)
- 微信5.0.3.1去反编译异常
- 类方法与实例方法的区别
- Microsoft Azure Premium Storage SSD Test