Mail cleanup from ksh script, keeping 50 most recent msgs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail cleanup from ksh script, keeping 50 most recent msgs
# 1  
Old 11-04-2009
Mail cleanup from ksh script, keeping 50 most recent msgs

I found some posts describing how to completely clean out a mailbox in Unix/Linux. But I want to keep the 50 most recent messages. Any ideas out there?

Thanks!
# 2  
Old 11-04-2009

What format is your mailbox?

Mbox? Maildir? Or something completely different?
# 3  
Old 11-04-2009
mbox.

Last edited by OPTIMUS_prime; 11-06-2009 at 10:11 AM.. Reason: New detail not showing as updated (not sorting to top)
# 4  
Old 11-06-2009
More detail provided

For example, if I have 3 messages in my system mailbox, and I read one and exit mailx, I see these messages:
Saved 1 message in /home/users/tiger/mbox
Held 2 messages in /var/spool/mail/tiger
I would like to clean up /var/spool/mail/tiger (leaving most recent 50 messages) without putting anything in /home/users/tiger/mbox. Alternatively, I could completely clean out /var/spool/mail/tiger and put the 50 most recent messages into /home/users/tiger/mbox.

Whichever is easier, I'm not choosy.

Thanks for your time and assistance.

Last edited by OPTIMUS_prime; 12-08-2009 at 04:33 PM.. Reason: corrected spelling
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh Searching for a string within a file and keeping a count= get the following Sample01=: command

I have a script that goes through a 24 hr logfile, And i want to count the instances of a Test01 to 83 and output the sum of all the instances over 24hrs #/bin/ksh cat $parse_data | awk '/'$time$i'/ {for(x=0; x<=16; x++) {getline; print}print "--" }' > _hr.txt for... (2 Replies)
Discussion started by: k00061804
2 Replies

2. Shell Programming and Scripting

AIX .ksh script freezes when using the mail -s command

Hello I am trying to send an email when a .KSH script is run on an AIX Machine. This email will only include a subject line that is made up of variables from within the script, and is as follows: CURRENT_DATE=`date +%Y%m%d` TIME=`date` ADMIN="myname@domain.com" date block () { ... (4 Replies)
Discussion started by: jimbojames
4 Replies

3. Shell Programming and Scripting

recent test -e ksh incompatibility in hpux?

On a very new (11.31) hpux machine, I can no longer execute shell fragements like: if ; then . .profile.foo fi and get "ksh: test: argument expected" if I convert this to -d or -f as appropriate (which I've not had to do on older versions of hpux (11.23) nor any other unix platform... (9 Replies)
Discussion started by: Peeter Joot
9 Replies

4. Shell Programming and Scripting

pid.cleanup script.

Hi guys! I have a directory in the production environment from which i have to delete files older then 40 minutes with .pid extention. I wrote a script below for the purpose. #!/bin/bash # # Script to delete specific file older than N minutes. # OLDERTHAN="40" #40 minutes ... (6 Replies)
Discussion started by: sajid.shah
6 Replies

5. UNIX for Advanced & Expert Users

Table Cleanup Script

I needed some help with a script to fetch and delete all records prior to 3 days from now connecting to sybase from sunos. I wrote the following script but not working..can someone please guide me with my code. Thanks #!/bin/ksh ##GET PREVIOUS DAY DATE dt=`date | awk... (3 Replies)
Discussion started by: moe458
3 Replies

6. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

7. Shell Programming and Scripting

ksh scripting: Extract 1 most recent record for unique key

I'm loading multiple delimited files into an Oracle DB using sqlldr on Unix. I would like to get only the most recent record per each unique key. There may be multiple updates for each key, but I only want the most recent one. There is a date column in my delimited files, so I'm using cat to... (2 Replies)
Discussion started by: OPTIMUS_prime
2 Replies

8. Shell Programming and Scripting

Cleanup script

Hi! I would like to write a script which remove some files, all beginning with the same prefix : prefix.1 doc/prefix.2 ../prefix.3 etc. So, I would create a file and chmod it executable. But I dont know how to pass a variable to a script. I would like to write something like ... (2 Replies)
Discussion started by: tipi
2 Replies

9. Shell Programming and Scripting

User Cleanup Script

Hi Guys, I've got an system setup to act as an sftp server. I have a script that allows me to create chroot users running a custom shell within their home directory, it also creates a subdirectory that they can write into. I'm trying to write a script (that I can cron at a later date) that checks... (3 Replies)
Discussion started by: King_Brucie
3 Replies

10. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies
Login or Register to Ask a Question