The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cut - columns with formatted Output dhanamurthy Shell Programming and Scripting 9 05-19-2008 11:20 AM
Formatted Output dhanamurthy Shell Programming and Scripting 6 05-13-2008 03:30 AM
Formatted output - awk dhanamurthy Shell Programming and Scripting 3 05-12-2008 12:25 AM
formatted output with commas joeyg Shell Programming and Scripting 4 03-04-2008 03:54 PM
Formatted output in KSH psynaps3 Shell Programming and Scripting 1 07-05-2006 09:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
mbak mbak is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 18
mailing customized and formatted ls -lt command output

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
  #2 (permalink)  
Old 10-11-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,436
What you need is:

Code:
...
ls -lt $DIR | awk '{print "Owner Date Timestamp FileName"}{print $3,$6,$7,$8,$9}'
...


Last edited by danmero; 10-11-2008 at 11:14 AM..
  #3 (permalink)  
Old 10-11-2008
mbak mbak is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 18
mailing customized and formatted ls -lt command output

Thank you,
And how do I mail the output of this 'ls' command, also I just need the number part from Filename ($9), i.e., 032508 from filename 'bma_slfpay$/#:032508AA'
  #4 (permalink)  
Old 10-11-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,436
This should work for 6 digit's number.

Code:
ls -lt | awk '{print "Owner Date Timestamp FileName"}{print $3,$6,$7,$8,substr($9,match($9,/[0-9]/),6)}'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0