Write a shell program to back up the configuration file in the system File :#! /Bin/bash // define the script execution environment # filename: mulubei // define the script file directory i0 // define the variable to be 0 find/-nameconf & gt; file // list found in the root directory...
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 This article is from the "Happy first" blog