Page 1 of 5 123 ... LastLast
Results 1 to 10 of 44

Thread: Sync Script

  1. #1
    Join Date
    Sep 2008
    Location
    metro detriot area
    Beans
    313
    Distro
    Ubuntu 14.04 Trusty Tahr

    Question Sync Script

    wrote a script to sync my netbook music with my server music and everything was fine.

    but if for some reason lets say i run it accidently and i'm not connected to my network, i just wiped my netbook music

    here's what i got so far:
    Code:
    Sudo mkdir /media/ServerMusic/
    mount -t cifs -o user=Justin,password=****** //192.168.1.108/Public-3/Music/ /media/ServerMusic/
    rsync -v -P --delete --min-size=500 -r -u /media/ServerMusic/ /home/forbees/Music/
    umount /media/ServerMusic/
    rm -r /media/ServerMusic/
    i need to have the --delete option in rsync (say i sync it and realize i hate some music, when i delete it from the server i don't want it still on the netbook



    i want an if statement in here somehow, but i'm not sure how to do it

    something like, the first command in the script should be a ping test, if ping doesn't work end the script, if ping does work continue


    ooorrrrr, if the server music gets mounted to the created directory continue, if the mount failed, or even in the mounted folder is empty stop the script


    what can i do here to ensure i can keep the --delete and not have to worry about losing my music if the mount fails?
    Last edited by Forbees; July 19th, 2010 at 02:28 AM. Reason: included script

  2. #2
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Sync Script

    After you execute mount, there will be a variable $?. If this variable is zero the mount was successful, otherwise not.

    I think.

  3. #3
    Join Date
    Sep 2008
    Location
    metro detriot area
    Beans
    313
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Sync Script

    how would you write that in the script?

  4. #4
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Sync Script

    Type "man bash" in the terminal for a general description of bash.


    Here is basically what you need to do:

    Code:
    if [[ 0 == $? ]]
    then
        proceed_as_normal
    else
        error_message
    fi
    Note that the spaces in the "if" expression are essential.

  5. #5
    Join Date
    Apr 2006
    Location
    Fresno CA
    Beans
    2,790
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Sync Script

    I use Unison to sync folders between my laptop and desktop over WiFi using NFS. I never have any surprises.
    Thank a veteran -- George 8)
    Internet Coach & Writer
    Personal Blog -- 3 Joes' Blog

  6. #6
    Join Date
    Sep 2008
    Location
    metro detriot area
    Beans
    313
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Sync Script

    i've had problems with unison and security before (since you have to login to access the finals)

    i'll try out that code once i'm done resyncing my netbook (reasons why i'm looking into this script . . i ran it when i wasn't connected, synced my music folder with an empty folder lol)

    hope it works

  7. #7
    Join Date
    Sep 2008
    Location
    metro detriot area
    Beans
    313
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Sync Script

    Quote Originally Posted by Zorgoth View Post
    Type "man bash" in the terminal for a general description of bash.


    Here is basically what you need to do:

    Code:
    if [[ 0 == $? ]]
    then
        proceed_as_normal
    else
        error_message
    fi
    Note that the spaces in the "if" expression are essential.


    whats the "fi" at the end for? is that a typo or needed lol

  8. #8
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Sync Script

    This may be obvious, but remember to put the if precisely after the mount command.

  9. #9
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Sync Script

    The fi is necessary. It defines the end of the if block. I would recommend reading man bash.

  10. #10
    Join Date
    Sep 2008
    Location
    metro detriot area
    Beans
    313
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Sync Script

    k, just wanted to make sure, i only have a little programming knowlege

    (basic, C++, java) back in highschool, so i wasn't sure if a script needed something to define the end or not (some basic level macro programing IF commands only work with one line of code, than assume the next line isn't a part of it)

Page 1 of 5 123 ... 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
  •