Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Howto send an email via the command line?

    I have a script that first backups a db and then ftps it to a remote server.

    How can I do a test that says if all that worked email me to tell me everything is OK, else tell me something is wrong?

    It's a cron job btw.

    Thanks

    Amy

    PS just the commands to email me would be fine, but the conditional stuff is a mystery to me too!

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Can't really answer your questions when you don't tell us what language or shell you are using for your scripting. Perl? sh (Bourne Shell)? bash (Bourne Again Shell)? csh (C-Shell)? ksh (Korn Shell)?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    whoops :o

    bash on redhat 7.2 sorry

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Hmmm conditional statements in bash are fairly straight forward

    http://steve-parker.org/sh/test.shtml

    As for sending mail you can use the linux mail command. Of course I seem to recall that when you run a cron job a mail gets sent to root regardless unless it was disabled in your scripting. Has anyone checked root's email lately?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that test page looks good and should help me with the scripting side of it.

    However, I was wondering if you could give me a hand with 'mail'.

    for e.g. I want to do a test to see if something's worked and if it has then something like this to happen.

    mail ( amygdala@home.com, subject="HEY IT WORKED", body="at so and so time etc." );

    Now I know that isn't the syntax, but from the small mail --help it didn't help me work it out how to do that

    Also, I was wondering how i might do the following (pushing luck here with you guys but I a newbie). Currently I run a backup:-

    tar -czf sitebackup23-01-03.tar.gz /home/virtual/site/

    I was wondering is there anyway of automatically getting the shell to put in the current date, so I can constantly automatically add to backups without overwriting previous ones?

    I promise I'll stop asking newb questions in a bit!!!

    Amy

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    if[expression]
    then
    mail username -s "Subject of Email"
    Content of Email
    Ctrl-d
    fi
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you thank you thank you thank you.

    Did I thank you?

    Amy

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well i'd make sure everything works first. lol

    As far as the backups do you mean put the current date as part of the file name?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Spookster As far as the backups do you mean put the current date as part of the file name? [/B]
    Yep. Exactly that.... it would be better than using a static filename which would then get overwritten every time a backup was made.

    Know a way?

  • #10
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Shouldn't be too hard. Just grab a timestamp from the system and use that as the filename.

    Post the portion of your script where you have set the filename for the backup.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #11
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $mysqldump -uusername -ppword dbname > /home/amygdala/backups/dbname-DATE.sql

  • #12
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone know how to add the date in dynamically using the command line in bash?

  • #13
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ok try this:


    $mysqldump -uusername -ppword dbname > /home/amygdala/backups/dbname-`date +%d_%m_%y`.sql
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #14
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just the job. Thanks


  •  

    Posting Permissions

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