mailing customized and formatted ls -lt command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mailing customized and formatted ls -lt command output
# 1  
Old 10-10-2008
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 {} \Smilie -->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  
Old 10-11-2008
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  
Old 10-11-2008
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  
Old 10-11-2008
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)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Customized command excution

Hi, The below commands will be inside a KSH script and SOLARIS machine. Command-1 //Executes in 10s,5s,..5mins,etc TIMER = Look for Command-1 execution status - IF finished in 25secs move to next command in the script IF NOT kill above command and move to next command. Command-2 Any... (9 Replies)
Discussion started by: penqueen
9 Replies

2. Programming

Formatted output in PERL

Hi Techies, I'm a newbie to PERL, Please help me with following problem. I have an input text file like below cat Input.txt 418673132,P 492538858,P 384535478,P 521522357,I 529435679,I 183617024,P 184414408,I 735510689,P 736238343,I 411642045,I 412690979,I 104232783,I (2 Replies)
Discussion started by: mahi_mayu069
2 Replies

3. HP-UX

Formatted TOP command output in file

Hi All, I want generate HP-UX overall system performance report. I tried executing top command and write that out put to file. but am not able to view the report in proper format. I can see report like below in file but i can see properly in terminal. Please suggest how can i get... (2 Replies)
Discussion started by: lravip123
2 Replies

4. UNIX for Dummies Questions & Answers

Request for Formatted Output

Can you please tell me how to just get only the output of dealers I & V information along with their subtotals in the next line of the file and create a new file, The dealer position along with corresponding totals may change everyday to any position above or below in the file, please help Thanks (2 Replies)
Discussion started by: Ariean
2 Replies

5. Shell Programming and Scripting

Formatted Output

Hi I have the following lines in a file SWPRC000001NOT STATED 1344 SWPRC000001NOT STATED 1362 SWPRC000001NOT STATED 1418 SWPRC000001NOT STATED 1436 SWPRC000001NOT STATED ... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

6. Shell Programming and Scripting

Formatted output - awk

Hi I have the following records in a file SABN YOURTUBE 000514 7256 SACN XYOUDSDF 000514 7356 SADN KEHLHRSER 000514 7656 SAEN YOURTUBE 000514 7156 SAFN YOURTUBE 000514 7056 I need to put this in the format like this printf '%s %-50s %6s %-6s\n' I am not going to read individual... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

7. Shell Programming and Scripting

formatted output with commas

var=12345 echo $var >>>12345 printf "%8.1f \n" $var >>> 12345.0 How to get this as 12,345? I suppose I could break into sections by dividing by 1000 or 1000000. But, is the a trick to this? (4 Replies)
Discussion started by: joeyg
4 Replies

8. UNIX for Dummies Questions & Answers

Mailing the output which is there in remote server

Hi all, I have a script which logs in to the remote server with FTP and with the user id/password and list the files in the path of remote server where thefiles resid.i need to email this output(i.e wether the files are present on not under the path) to my email id. Can u please let me know as... (2 Replies)
Discussion started by: OSD
2 Replies

9. Shell Programming and Scripting

Mailing the output which is there in remote server

Hi all, I have a script which logs in to the remote server with FTP and with the user id/password and list the files in the path of remote server where thefiles resid.i need to email this output(i.e wether the files are present on not under the path) to my email id. Can u please let me know as... (2 Replies)
Discussion started by: OSD
2 Replies

10. Shell Programming and Scripting

Formatted output in KSH

Hi, Is there some way to get formatted output in ksh? Something like a properly alligned tabular format. I tried adding '\t' to echo statements, but it doesn't come properly alligned 'hello' A simple Hello 'helloworld' A helloworld statement I need the second coloumn to... (1 Reply)
Discussion started by: psynaps3
1 Replies
Login or Register to Ask a Question