#!/bin/bash

if [ -z $1 ];then

        echo 'Usage: cutlog [log path]'

else

        if [ ! -e /data/wwwlogs/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m") ];then

                mkdir -p /data/wwwlogs/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")

        fi

        name=$(basename $1)

        y=$(date -d "-1 day" +%Y-%m-%d)

        cp $1 /data/wwwlogs/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/$y-$name

        echo ''> $1

fi