Re: Help with Crontab script?



robert wrote:
Hello, I'm rather new to linux and was wondering if someone could
assist me in writing a crontab?

I want to tar a file daily and send it to an email address.

I think I can figure out how to write a crontab to tar the file daily
but how do I write one to email it as an attachment daily? I haven't
quite figured out email in linux yet.

Thanks for any help.



The simplest way to send an email with an attachment from a script is to use "mutt". For example (watch for wrapping!):

echo "File is attached" | mutt -s "Daily Report" -a /tmp/report.tar.gz someone@xxxxxxxxxxxxx

If you don't want a text body, you still need the echo:

echo | mutt ........

So the whole script is pretty damn simple:

--------------------------
#!/bin/bash

tar czf /tmp/report.tar.gz /path/to/the/file.txt
echo "report" | mutt -s "report" -a /tmp/report.tar.gz self@xxxxxxxxxx
--------------------------

Warning, example is untested and needs some customization, anyway.

--
Ogre
.



Relevant Pages

  • Re: Aix Password Migration from 4.3 to 5.2
    ... I even wrote a script to package up all the users from the old box and then "add" them onto the new box. ... tar -cdvf $TMPDIR/usertrans/$u1.tar $g3 ... echo "...Setting up base groups" ... echo "....untaring the transfered datafiles" ...
    (comp.unix.aix)
  • Re: A silly question about tar
    ... replace echo with tar, and you see that tar is going to try and ... $ echo first.txt ... $ cat first.txt ... I tarred this test directory up into a tarball called first.tar.gz. ...
    (Debian-User)
  • Use tar to append?
    ... I have a backup script which I run on some sort of regular ... I use tar to create an archive, ... echo "Verifying $path...." ... errors in verify" | wall ...
    (Fedora)
  • [PATCH] gcov: fix documentation
    ... Commonly available versions of cp and tar don't work well with special ... Sample script to gather coverage meta files on the build machine ... +echo Collecting data.. ... echo "Could not create file $DEST" ...
    (Linux-Kernel)
  • Re: Use tar to append?
    ... I use tar to create an archive, ... into pieces of CDROM size and write to CDROMs. ... echo "Verifying $path...." ... marginally faster, perhaps, since I compress), but see ...
    (Fedora)