Thursday, 15 January 2015

bash - Keeping multiple Shell Script into one to backup log files -


I have wrapped up the 10th number of server logs to back up.

#! / Bin / sh filePath = "/ var / opt / appserver / app / example / default / log / error .log.10" backup.dir = "/ backup_app-n / app / default / log" ### Start the process ### # Md5File = `md5sum $ filePath | Awk -F "" '{print $ 1}' `#echo $ md5 file name-name =` basename $ filePath | Sed 's /. [0- 9] \ + // g'` #echo $ fileName while [1] MD5 pre = $ md5File md5File = `md5sum $ filePath | Previous $: $ md5 file "if [$ md5 pre! = $ Md5File]; then exe_date = 'date' +% m% d% Y_% H% M% S'cp $ filePath $ backupDir / $ fileName- $ exe_date echo "Copy:" $ filePath "$ backupdir / $ fileName- $ exe_date Gzip $ backupDir / $ fileName- $ exe_date fi sleep 3 done < / Code>

I have some more similar scripts for the same functionality, but only replace filePath . Now I want to create a script to run the same thing. (To keep the same argument in a script, not concurrently)

I did the following things - I have a configuration file - test.config where I have all FilePath and path to config files.

  #! / Bin / sh while reading path while doing [1] file = path = "$ path" backupDir = "/ backup_app -an / app / default / log" ### initiate the process #### md5File = `md5sum $ FilePath | Awk -F "" '{print $ 1}' `#echo $ md5File" md "filename =` basename $ filePath | Sed 's /. [0- 9] \ + // g '~ #echo $ fileName "file" md5 pre = $ md5 file md5file = `md5sum $ filePath | Previous $: $ md5 file "if [$ md5 pre! = $ Md5File]; then exe_date =` date '+% m% d% Y_% H% M% S'` cp $ filePath $ backupDir / $ fileName- $ exe_date echo "Copy: $ backupdir / $ fileName- $ exe_date as" $ filePath "Gzip $ backupDir / $ fileName- $ exe_date & Lt; In test.conf sleep 3 done  

and test.config , I place the path

  / var / opt / AppServer /App/instances-0/default/logs/error.log.10/var/opt/AppServer/App/instances-1/default/logs/error.log.10/ var / opt / AppServer / App / Example-2 / Default / log / error.log.10 // password / apsarver / app / instance -3 / default / lodge / terror.log.10  

I am running script differently , I'm getting results but my revised form is not working properly.

I think the problem is for while loop . Once inside, it takes 4 paths and executes for 2 times, the loop starts from the beginning, it can not preserve the last position !!!

I have questions - what will be possible solutions?

Is my view so good to run many scripts in this way?

Do I have any other way to achieve this?


No comments:

Post a Comment