Write a shell program to back up the configuration file in the System File
Code implementation:
#! /Bin/bash // define the script execution environment
# Filename: mulubei // defines the script file directory
I = 0 // defines that the variable is equal to 0
Find/-name conf> file // list file found in the root directory, assigned to file
If [-d/tmp/conf]; then // checks whether the file exists,
Echo "/tmp/conf already exists." // The output file already exists.
Else // loop statement
Mkdir/tmp/conf // create a directory
Echo "tmp/conf is created." // the file has been created.
Fi // file ended
While read LINE // a loop statement to read and assign values to the LINE variable
Do // do in a loop statement
DIRS = $ LINE; // assign the LINE variable to DIRS.
BACKUP = "/tmp/conf/backuptailpolici2.16.tar.gz" // scheduled variable backup,
Tar-zcvf $ BACKUP $ DIRS // use tar for compression
I = $ ($ I + 1) // sum of I values of the cyclic variable
Done <file // indicates that the loop body ends and the value is read from the file.
This article is from the "Happy first" blog