6. Script timed Tasks
# 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. View the UID of the current user
root @kallen :/usr/data/kallendb_backup # ps-ef | grep UID uid pid ppid c stime TTY Span class= "hljs-constant" >time cmd root 2872 2384 0 09: 43 pts/2 00 : 00 : Span class= "Hljs-number" >00 grep--color=auto uid
8. Simulate a progress bar with the Shell
#!/bin/bash # # Progress Bar # Print # to view th E 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
In the application of shell scripting, it is sometimes necessary to use a graphical interface case, for example, the default CP copy file is silent mode. You cannot see the progress and percentage of the copy.
Dialog is the tool that provides a graphical interface for the shell, which provides a variety of graphical interfaces for Shell scripting, and today introduces the dialog-bar graphics functionality provided by the tool.
The dialog instruction can be run separately. Format is
"Copy""files"67010
Note:
Title indicates the caption of the graphics progress bar.
Gauge is the body content. Progress bar height is 6, width 70. Show run progress of 10%
forin {1..100do1; echo$i‘Copy‘‘I am busy!‘10700done
In the following cases, the number of source files is counted. It then calculates the percentage of the copied file, providing a display of progress in the shell.
The script has two parameters. The first parameter is the source file path, and the second is the destination path.
Let's say your application case is different and can be used as a minor change.
#!/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 $ is destination dir. Dir= $/* des= $ # Test The destination dirctory whether exists[- D $des] &&Echo "Dir Exist"&&Exit 1 # Create The destination dirctoryMkdir$des # Set counter, it would auto increase to the number of# source file. I=0 # Count of the number of source fileN= 'Echo $/* |wc-w ' forFileinch`Echo $dir` Do # Calculate Progresspercent=$ (( -* (++i)/n)) Cat <<eof XXX$percentCopying file$file... XXX Eof/bin/cp-r$file $des&>/dev/null Done| Dialog--title"Copy"--gauge"Files" 6 -Clear
Effect
9.Echo output
Feature Description: Display text
Syntax
echo[ -ne ] [ 字符串 ] 或 echo[ --help ] [--version ]
Number of references:
-n 不要在最后自己主动换行-e 若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出; \b 删除前一个字符; \f 换行但光标仍旧停留在原来的位置; \r 光标移至行首。但不换行; \t 插入tab。 \v 与\f同样; \nnn 插入nnn(八进制)所代表的ASCII字符。--help 显示帮助--version 显示版本号信息
Top Picks
LNMP Environment Construction--nginx Chapter
Configuring the local Yum source in RHEL6.5
Installation and use of Zabbix under Ubuntu
MySQL Dual master hot standby problem processing
Shell Step by Step (4)--cron & Echo