Friday 17 February 2012

Script to get today's files and copy them back



#!/bin/sh

# List all the files with the current date in given directory
latestFiles(){
target=$1
myvar=`date "+%h %d"`

for file in `ls -al $target | grep "$myvar" | grep ':' | sed 's/[-drwx]* *[0-9] *[a-zA-Z0-9]* *[a-zA-Z0-9]* *[0-9]* *[a-zA-Z]* [0-9]* *[0-9]*:[0-9]* *\.*//'`; do
cmd="`echo cp $file $localFile` `echo $file | sed 's/\//_/g'`"
echo $cmd
`$cmd`
done
}

# Using Bladelogic NSH locations
latestFiles //servername/users/user1/tomcat/log/*.log