Find the answer to your Linux question:
Results 1 to 3 of 3
I would like to create a script that will run every day and save all the messages in the inbox and save them to a file then delete the old ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187

    bash script - save mailbox messages.


    I would like to create a script that will run every day and save all the messages in the inbox and save them to a file then delete the old messages.
    Right now I am doing this manually and would like this automated. This is how I am doing it now.

    I go to my mail archive folder and type:
    mail
    > s 1-### mbox.temp###
    > d 1-###
    > q

    Now if the number of messages were the same everyday then I would be able to do this a lot easier. Since I dont know if there is any wild cards I could use for the total number of messages does anyone know another way to do this?

    Thanks

  2. #2
    Just Joined!
    Join Date
    May 2011
    Location
    Central FL
    Posts
    91
    Code:
    #!/bin/sh
    cp mbox mbox.`date +%F` && gzip mbox.`date +%F` && : > mbox
    That would copy the current mbox to a new file (gzip it - just because saving space doesn't hurt), then clear the old mbox. You could just create a file with those contents and run it once daily via cron.
    Last edited by dayid; 04-14-2012 at 03:11 AM. Reason: clarify

  3. #3
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    well I know this is old but I figured out how to do it. It was so simple I feel bad that I didn't think of it sooner. The good new is I have automated this process and removed it from my daily tasks.

    first i run
    Code:
    cp /var/spool/mail/<username> newmail.file
    to save the email to a file called newmail.file
    then I run
    Code:
    > /var/spool/mail/<username>
    to delete the mail

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •