shell programming

Discussion in 'Programming' started by asgsoft, Jul 13, 2010.

  1. #1
    Hey Everyone,

    Shell programming is something I haven't learnt or tried before.. but I kind of need it to automate backing up my website.

    At the moment, I have:

    #/bin/bash
    /bin/tar czPf /home/cpanelusername/etc/files/wp-content-weekly.tar.gz /home/cpanelusername/public_html/wp-content/
    Code (markup):
    but how do I get it to email me the file wp-content-weekly.tar.gz and then delete it?

    Is that possible?

    Thanks for ur help in advance
     
    asgsoft, Jul 13, 2010 IP
  2. Kaimi

    Kaimi Peon

    Messages:
    60
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    Hmm for backup, I use rdiff-backup. It is incremental which means only the difference is stored, saving a whole heap of space, and can be restored to any given time.
     
    Kaizoku, Jul 15, 2010 IP
  4. KenJackson

    KenJackson Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Email? Ug!

    What are you running on the destination computer? If you are running Linux, FreeBSD or maybe even OSX, you should be able to setup a cron job to grab it and delete it. Do you have ssh or ftp access to your account?

    If you are running Windows, you might still be able to do something like that, but not easily.
     
    KenJackson, Jul 17, 2010 IP
  5. asgsoft

    asgsoft Well-Known Member

    Messages:
    1,737
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    160
    #5
    I have a Linux OS as my server running cpanel. A cron job that can grab the backup file, email it and then delete it?

    How so?
     
    asgsoft, Jul 21, 2010 IP
  6. KenJackson

    KenJackson Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No, I mean Linux running on the receiving end--the computer you are copying the file to. That's probably your home computer. In that case, the cron job could run this command, where server.com is your server. I'm assuming /home/cpanelusername/ is your account's home directory.

    scp server.com:etc/files/wp-content-weekly.tar.gz backups/

    But if you really want to email the backup archive from the server, you can probably do that instead, assuming you don't hit a size limit somewhere. Find out if it has mailx or similar--a command-line email tool. It's probably /usr/bin/mail or /usr/bin/mailx. If it has it, find the syntax, which varies a little from version to version. Some have an a -a switch for attachments and some don't. If you have SSH access, you can use the command man mail to see.

    Without using the attachment switch, this command may work:
    base64 etc/files/wp-content-weekly.tar.gz | mail -s "Weekly backup" you@yours.com
    Code (markup):
    The base64 command encodes it as text. You'll need to unencode it at home. If you're using Windows, you may have to find a base64 utility. (Every other OS comes with one standard.)
     
    KenJackson, Jul 21, 2010 IP
  7. Alexandros1

    Alexandros1 Peon

    Messages:
    332
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Even though there are various graphical interfaces available for Linux the shell still is a very neat tool. The shell is not just a collection of commands but a really good programming language.You can automate a lot of tasks with it, the shell is very good for system administration tasks, you can very quickly try out if your ideas work which makes it very useful for simple prototyping and it is very useful for small utilities that perform some relatively simple tasks where efficiency is less important than ease of configuration, maintenance and portability.
     
    Alexandros1, Jul 25, 2010 IP