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 shell script writing application, sometimes need to use the graphical interface case, such as the default CP copy file is silent mode, can not 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 progress bar Graphics feature provided by dialog.
The dialog instruction can be executed separately, in the form
"Copy""files"67010
Note:
Title indicates the caption of the graphic progress bar,
Gauge is the body content, the progress bar height is 6, Width 70, display progress is 10%
forin {1..100do1; echo$i‘Copy‘‘I am busy!‘10700done
In the following case, by counting the number of source files, and then calculating the percentage of the copy file, the display of progress is provided in the shell. The script has two parameters, the first parameter is the source file path, and the second parameter is the target path. If your application case is different, you can use it as a minor modification.
#!/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 ]
Parameters:
-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