Log_bak.sh code bin_home = & quot;/home // bin & quot; Folder_DEPLOY = $ bin_home & quot;/log & quot; log_back = & quot;/home/logback & quot; functioncheckDerectory () {if [& quot; 'ls-
Log_bak.sh code
Bin_home = "/home // bin"
Folder_DEPLOY = $ bin_home "/log"
Log_back = "/home/logback"
Function checkderecloud (){
If ["'ls-A $ Folder_DEPLOY '" = ""]; then
# Do something
Echo false
Else
# Do something
Echo true
Fi
}
Function checkFiles (){
If ["'ls-A $ Folder_DEPLOY '" = ""]; then
# Do something
Echo false
Else
# Do something
Echo true
Fi
}
Dates = $ (date-d "2 days ago" + % Y-% m-% d)
Files = "log." $ dates "*"
Cd $ bin_home
If [-f $ files]; then
Mv $ files $ Folder_DEPLOY
DerecResult = $ (checkderecresult)
# Echo $ derecResult
If $ derecResult; then
# Do something
# Echo "now tar ..."
Cd $ Folder_DEPLOY
Tarfilename = "converter. log." $ dates ".tar.gz"
Tar-czvf $ tarfilename *
# Echo "now mv ..."
Mv $ tarfilename $ log_back
# Echo "rm-rf ..."
Rm-rf $ files
Fi
Fi
Add a Task Scheduler
View task plans
Crontab-l
Add a Task Scheduler
Crontab-e
10 0 ***/home/bin/log_bak.sh
Restart crontab
Su root
Service crond restart
OK.