0

I've some files in directory /app/me/all_off which filename like below :

  • access_log
  • alarm-batch
  • alarm-service-root
  • db_wrapper_access_log
  • db_wrapper_api_service
  • moqueue-job
  • mt_push_api_service
  • mtqueue-job
  • nbp_request_handler
  • profile_api_service
  • promo_api_service
  • queue-service-root

then, it files formatted with extention .log and they generated everyday with formatted : xxxx.log.20190101

therefore, I want to archive and move all of that files (files with last generated one day before now) into /app/me/all_off/backup/ Everyday at 12AM. But I want to backup that files in specific directory (as based on their name) like example :

  • /app/me/all_off/backup/access_log/access_log.log.2019010

Is there any problem-solving for my case ?

I'm using Shellscript for Archive and Move that file, but it just only moved into /app/me/all_off/backup/ . Below for my Shellscript :

(#!/bin/bash ----> "(" just remarks

date1=date -d "yesterday" +%Y%m%d

date2=date -d "yesterday" +%Y-%m-%d

logPathMove=$logPath"backup/"

logPath='/app/me/all_off/'

all=ls -ltrh *log* *log | awk -F ' ' '{print$9}' | awk -F '.' '{print$1}' | sort | uniq -c | awk -F ' ' '{print$2}'

cd ${logPath}

gzip -9 *.${date1}

gzip -9 *.${date1}.log --------> another format of filename

gzip -9 *log.${date2}.log --------> another format of filename

cd {logPath}

for i in *.gz; do mv ${i} ${logPathMove}; done

0

Its a bit hard to exactly make out what you want to do. However here is a general trick to help debug shell scripts: Put this line at the start of your script:

set -x

So if the script is:

b=1
echo a $b

Running it produces

a 1
$ 

Whereas if you make it

set -x
b=1
echo a $b

it produces

+ b=1
+ echo a 1
a 1
$

In other words you'll see what commands are being executed along with the variable substitutions along with the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.