Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: need a script to turn off a program, check for rsync

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    need a script to turn off a program, check for rsync

    Hello I need to make an automated server backup for my ubuntu 10.04.2 server

    It is a samba server via hamachi.

    I plan on using cron to automate rsync once a month but before rsync runs i need a script of some kind to disconnect hamachi and then wait until rsync completes to turn hamachi back on.

    How would i do this?

    Someone said i need my rsync job to touch a file when it starts and remove it when it finishes im not to sure what he meant by that.

  2. #2
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,126
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    I dont know what hamachi is but does it run as a process?
    expect and TCL/Tk scripting might make you very happy.
    else i would assume to use bash and do a kill command for samba,
    then run the back up script, then reconect (init) samba when the back up completes.

    is that an accurate psudo-code of what you want to do?
    (I'll help you script it if it is.)
    ~Conradin~

  3. #3
    Join Date
    Jun 2009
    Beans
    44

    Re: need a script to turn off a program, check for rsync

    In your cron script something like this should work..

    #!/bin/bash
    #Stop hamachi
    sudo hamachi -c /etc/hamachi stop
    #Wait for hamachi to stop
    sleep 15

    #insert your rsync commands

    #Wait for xx seconds after rsync has completed
    sleep 30
    #Restart hamachi
    sudo hamachi -c /etc/hamachi start


    Why do you need to take hamachi down, to stop people writing to the samba shares?

  4. #4
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    atca: yes i would like to keep people from writing to the samba folder while it backs up. but are you saying that i can kill samba and not worry about hamachi. I would assume that i should not have anyone using my shares while its backing up unless im totally wrong. Is there a better way at doing that.

    Thank you for the script

  5. #5
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    so i would do this then

    $ sudo crontab -e
    ______________________________________

    # m h dom mon dow command
    0 0 * * * /usr/bin/clamscan -v -r /srv

    0 9 1 * *
    #!/bin/bash
    #Stop hamachi
    sudo hamachi -c /etc/hamachi stop
    #Wait for hamachi to stop
    sleep 15

    sudo rsync -g -o -p -a /srv/samba/ /media/Backup/

    #Wait for xx seconds after rsync has completed
    sleep 30
    #Restart hamachi
    sudo hamachi -c /etc/hamachi start
    _______________________________________________


    it doesnt seem right to me :/

  6. #6
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    nvm i found out

  7. #7
    Join Date
    Jun 2009
    Beans
    44

    Re: need a script to turn off a program, check for rsync

    I'd probably create a shell script with it in and use cron to call out to the shell script.

    Something along that principle should work it depends how you run hamachi really.

    Personally I think you'll find it easier not to mess with the networking but to take samba down instead. Using the follow repectively, I usually have awful issues bringing hamachi down and up cleanly.

    /etc/init.d/samab stop

    /etc/init.d/samba start

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Beans
    435
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    hmmm sleep is cool no point in processing an if a zillion times whilst copying...

    lock files are more for when you have multiple processes though; ie you which to determine if a group of processes launched from another script are running...

    what you want to do is create a function called i'm done; create a trap which launches the funtion which lanches hanachi again...

    eg
    Code:
    /etc/init.d/hama stop
    rsync files...
    rsync files...
    rsync files...
    
    function imDone()
    {
       echo "starting hamacho again all done..."
       /etc/init.d/ham start
    }
    
    trap imDone EXIT
    lemmie kno if you need help with this
    Last edited by mikejonesey; July 17th, 2011 at 11:06 PM.
    My personal website with blog n apps
    http://www.mikejonesey.co.uk/

  9. #9
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    Well when I bash the script samba_back that i made I get back an error stating samba is not installed and if I meant to install samba4 after that rsync goes to work and then i get the error after thats done... expected

    I checked under the dir /etc/init.d/samba but there is no samba directory under /etc/init.d/ maybe I needed to install samba4 ??!! :/

    When I do an aptitude install for samba it says I already have it installed along with samba-common and so forth.

    This seems very disturbing because I used to be able to use samba start ... stop
    Maybe that was on my first install this is my second go at samba im doing much better
    __________________________________

    Now getting back to what mikejonesey said:
    I am a little confused as to what this does and why I need it done this way. How exactly would I go about using this and whats the benefits of this method.

    I will start doing some research on i'm done functions.

    O_o

  10. #10
    Join Date
    Apr 2008
    Location
    US of A
    Beans
    23
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: need a script to turn off a program, check for rsync

    this is my script i made

    #!/bin/bash
    #Stop samba
    sudo /etc/init.d/samba stop
    #Wait for samba to stop
    sleep 15

    sudo rsync -v -g -o -p -a /srv/samba/ /media/Backup/

    #Wait for xx seconds after rsync has completed
    sleep 30
    #Restart samba
    sudo /etc/init.d/samba start


    if its any help

    does it use smbd instead of samba cause i think i read some where it does ill check this
    Last edited by plecebo.mc; July 19th, 2011 at 02:59 PM. Reason: added -v for verbose

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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