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/null
done | 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 显示版本号信息

热门推荐

Shell Step by Step (4) —— Cron &amp; Echo的更多相关文章

  1. Shell Step by Step (3) —— Stdin &amp; if

    4.输入输出 #! /bin/bash # Read users input and then get his name read -p "Please input your first n ...

  2. 精通initramfs构建step by step

    (一)hello world  一.initramfs是什么  在2.6版本的linux内核中,都包含一个压缩过的cpio格式 的打包文件.当内核启动时,会从这个打包文件中导出文件到内核的rootfs ...

  3. Step by Step Process of Migrating non-CDBs and PDBs Using ASM for File Storage (Doc ID 1576755.1)

    Step by Step Process of Migrating non-CDBs and PDBs Using ASM for File Storage (Doc ID 1576755.1) AP ...

  4. WPF Step By Step 系列-Prism框架在项目中使用

    WPF Step By Step 系列-Prism框架在项目中使用 回顾 上一篇,我们介绍了关于控件模板的用法,本节我们将继续说明WPF更加实用的内容,在大型的项目中如何使用Prism框架,并给予Pr ...

  5. Linux 学习 step by step (2)

      Linux 学习 step by step (2) Linux,想要我说爱你真的不容易了,尽管,你是ubutun,尽管,你有蛮界面.但是,操作你,还是没有操作windows那么的如鱼得水了.为了更 ...

  6. Step By Step(Lua输入输出库)

    Step By Step(Lua输入输出库) I/O库为文件操作提供了两种不同的模型,简单模型和完整模型.简单模型假设一个当前输入文件和一个当前输出文件,他的I/O操作均作用于这些文件.完整模型则使用 ...

  7. Step by step Dynamics CRM 2011升级到Dynamics CRM 2013

    原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...

  8. Step by Step 创建一个新的Dynamics CRM Organization

    原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...

  9. Step by step Install a Local Report Server and Remote Report Server Database

    原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 &g ...

  10. Step by step Dynamics CRM 2013安装

    原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处   SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...

随机推荐

  1. 转载:编译安装Nginx(1.4)《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19617.html 安装Nginx最简单的方式是,进入nginx-1.0.14目录后执行以下3行命令:./configuremakem ...

  2. as无法在vivo上安装程序解决

    1. vivo手机真的很麻烦,首先要确定vivo账号密码,允许安装后还一直失败.记录下解决方案 在工程目录的gradle.properties中添加android.injected.testOnly ...

  3. Fiddler抓包10-会话框添加查看get与post请求类型

    前言 在使用fiddler抓包的时候,查看请求类型get和post每次只有点开该请求,在Inspectors才能查看get和post请求,不太方便.于是可以在会话框直接添加请求方式. 一.添加会话框菜 ...

  4. LINQ学习之旅 (四)

    LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains 1.Group By/Having操作符 适用场景:分组数据,为我们查找数据缩小范围. ...

  5. 查看Linux端口的占用及连接情况

    [root@cloudplatform ~]# netstat -nap | grep 22066 | grep 127.0.0.1 -vtcp        0      0 :::22066    ...

  6. H 模拟水题

    n个人 小明编号为m 从编号为a的人开始数 起始数字为b 遇到素数duang 并反相 求小明应该说什么 Sample Input 310 2 //n m3 4 //a b3 32 64 13 8 Sa ...

  7. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

  8. BZOJ1925 [Sdoi2010]地精部落 动态规划

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1925 题意概括 给出n,n<=4200,问1~n这些数的排列中,有多少满足一下性质: 性质: ...

  9. 解决celipse中mybatis使用的时候xml没有提示的问题

    文件下载好以后点击Add会出现如下界面 上面是添加mapper的插件,再找到config的配置文件.和上面相似的操作安装以后就可以了

  10. Python2 - 基础2 - 数据类型和模块

    一.数据类型 标准数据类型(5): Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 其中数字类型有4种: int(有符号整型) 在3 ...