I'm trying to write a script to email the output of 'ls -lt' command that are 30 days old along with headers for eg. like owner, date, timestamp and a portion of some special character files like 'slfpay$/#:032508AA' in /home/test directory, I just want the numbers from the last field ($9), also the email I get contains the 1st line of ls -lt output along with subject and remaining output in the message body whereas the complete output should go to a message body.
# ls -lt
rwxr-xr-x 1 tik44 staff 7731 Oct 09 17:15 bma slfpay$/#:032508AA
rwxr-xr-x 1 tik77 staff 6701 Sep 13 09:47 bma slfpay$/#:054101AA
Output should look like,
Owner Date Timestamp FileName
tik44 Oct 09 17:15 032508
tik47 Sep 13 09:47 054321
----------Script--------------------------------
#!/usr/bin/ksh
set -x
DIR=/home/test
OLD=$(find $DIR -mtime +30 -exec ls {} \
-->this is ; and ) not smiley
if [ ! -z "$OLD" ]; then
LS=`ls -lt $DIR | ls -lt | awk '{print $3 " " $6 " " $7 " " $8 " " $9}'
echo |mail -s "`hostname`: Output from ls -l command" \
"user@test.com
user1@test1.com"
----------Script--------------------------------
Thanks