Shell Step by Step (4) —— Cron & Echo
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 & Echo的更多相关文章
- Shell Step by Step (3) —— Stdin & if
4.输入输出 #! /bin/bash # Read users input and then get his name read -p "Please input your first n ...
- 精通initramfs构建step by step
(一)hello world 一.initramfs是什么 在2.6版本的linux内核中,都包含一个压缩过的cpio格式 的打包文件.当内核启动时,会从这个打包文件中导出文件到内核的rootfs ...
- 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 ...
- WPF Step By Step 系列-Prism框架在项目中使用
WPF Step By Step 系列-Prism框架在项目中使用 回顾 上一篇,我们介绍了关于控件模板的用法,本节我们将继续说明WPF更加实用的内容,在大型的项目中如何使用Prism框架,并给予Pr ...
- Linux 学习 step by step (2)
Linux 学习 step by step (2) Linux,想要我说爱你真的不容易了,尽管,你是ubutun,尽管,你有蛮界面.但是,操作你,还是没有操作windows那么的如鱼得水了.为了更 ...
- Step By Step(Lua输入输出库)
Step By Step(Lua输入输出库) I/O库为文件操作提供了两种不同的模型,简单模型和完整模型.简单模型假设一个当前输入文件和一个当前输出文件,他的I/O操作均作用于这些文件.完整模型则使用 ...
- Step by step Dynamics CRM 2011升级到Dynamics CRM 2013
原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...
- Step by Step 创建一个新的Dynamics CRM Organization
原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...
- 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 ...
- Step by step Dynamics CRM 2013安装
原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处 SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...
随机推荐
- Oracle 11g服务器安装详细步骤——图文教程(系统 windows server 2012 R2)
Oracle 11g服务器安装的相关问题,下面小编就带大家一起来下载.安装. 方法/步骤 1 大家可以根据自己的操作系统是多少位(32位或64位)的,到官网下载相应的安装程序,如下图所示. 有一点需要 ...
- Laravel 的文件存储 - Storage
记录一下 Laravel Storage 的常见用法 内容写入磁盘文件 > php artisan tinker >>> use Illuminate\Support\Faca ...
- python 全栈开发,Day23(复习,isinstance和issubclass,反射)
一.复习 class A: def func1(self):pass def func2(self): pass def func3(self): pass a = A() b = A() print ...
- 步步为营-53-JavaScript
说明 :JS比较常用 1.1 常见的两种使用方式: 1.1.1 直接使用 <script>alert('Hello,World')</script> 1.1.2 引用 ...
- 01_kettle源码部署
一 kettle源码部署概述 1.从git上选择合适的版本,并down下来: 2.创建一个java项目,建立core,dbdialog,engine,ui,plugins文件夹,和一个lib文件夹: ...
- extern "C" 回顾
引入:在测试"extern "C" 与gcc, g++无关"时,使用到了extern "C"的概念,网上找篇文章回顾一下. 试验如下: te ...
- Spring事务传播行为
什么是事务传播行为 public void methodA(){ methodB(); //doSomething } @Transaction(Propagation=XXX) public voi ...
- Springboot 2.0 - 集成redis
序 最近在入门SpringBoot,然后在感慨 SpringBoot较于Spring真的方便多时,顺便记录下自己在集成redis时的一些想法. 1.从springboot官网查看redis的依赖包 & ...
- hihocoder 编程练习赛23
第一题:H国的身份证号码I 题意:一个N位的正整数(首位不能是0).每位数字都小于等于K,并且任意相邻两位数字的乘积也小于等于K.按从小到大的顺序输出所有合法的N位号码,每个号码占一行. 思路:dfs ...
- 【BZOJ5110】[CodePlus2017]Yazid 的新生舞会
题解: 没笔的时候我想了一下 发现如果不是出现一半次数而是k次,并不太会做 然后我用前缀和写了一下发现就是维护一个不等式: 于是就可以随便维护了