bash - shell script to create folder daily with time-stamp and push time-stamp generated logs -



bash - shell script to create folder daily with time-stamp and push time-stamp generated logs -

i have cron job runs every 30 minutes generate log files time-stamp this:

test20130215100531.log, test20130215102031.log

i create 1 folder daily date time-stamp , force log files in respective date folder when generated.

i need accomplish on aix server bash.

maybe looking script this:

#!/bin/bash shopt -s nullglob # line not compain when no logfiles found filename in test*.log; # files considered ones startign test , ending in .log foldername=$(echo "$filename" | awk '{print (substr($0, 5, 8));}'); # foldername characters 5 13 filename (if exist) mkdir -p "$foldername" # -p dont "folder exists" warning mv "$filename" "$foldername" echo "$filename $foldername" ; done

i tested sample, proper testing before using in directory contains of import stuff.

edit in response comments:

change original script this:

foldername=$(date +%y%m%d) mkdir -p /home/app/logs/"$foldername" sh sample.sh > /home/app/logs/"$foldername"/test$(date +%y%m%d%h%m%s).log

or directory created somewhere else, this:

sh sample.sh > /home/app/logs/$(date +%y%m%d)/test$(date +%y%m%d%h%m%s).log

bash shell unix cron aix

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -