Shell Step by Step (4) -- Cron & amp; Echo, stepcron

Source: Internet
Author: User

Shell Step by Step (4) -- Cron & Echo, stepcron

6. Script scheduled task

# 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 TIME CMD root 2872 2384 0 09:43 pts/2 00:00:00 grep --color=auto UID

8. simulate a progress bar with 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


In Shell script writing applications, graphical interfaces are sometimes required. For example, the default cp copy file mode is silent, and the copy progress and percentage cannot be seen. The dialog tool provides a graphical interface for Shell. It provides a variety of graphical interfaces for Shell scripts. Today we will introduce the progress bar graphical function provided by dialog.
The dialog command can be executed independently in the format
dialog --title "Copy" --gauge "files" 6 70 10
Note:

Title indicates the title of the graphic progress bar,
Gauge is the body content, the progress bar height is 6, the width is 70, and the display progress is 10%

for i in {1..100} ; do sleep 1;     echo $i | dialog --title 'Copy' --gauge 'I am busy!' 10 70 0; done

In the following case, the number of source files is counted, and the percentage of copied files is calculated accordingly. The progress is displayed in 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 cases are different, you can use them with slight modifications.

#!/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

Effect

9. Echo output

Function Description: display text
Syntax:

Echo [-ne] [String] or echo [-- help] [-- version]

Parameters:

-N: Do not wrap the line at the end.-e: if the following characters appear in the string, the line breaks them into special processing, instead of using it as a general text output. \ B deletes the previous character; \ f line feed, but the cursor remains at the original position; \ r move the cursor to the beginning of the line without line feed; \ t Insert the tab; \ v is the same as \ f; \ nnn inserts the ASCII character represented by nnn (octal); -- help displays help -- version displays version information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.