Results 1 to 4 of 4

Thread: Automated rsync shell script for syncing files

  1. #1
    Join Date
    May 2014
    Beans
    8

    Post Automated rsync shell script for syncing files

    Hey guys! I am writing an rsync script to automatically sync music between my computer and a portable media device. I need some help in improvising it .
    Assumtion: All scipts are chmod'ed to execute.
    This is the code that I used: walkman_sync.sh :
    Code:
    rsync -avrh --progress --exclude-from=/home/venkat/Music/walkman_exclude /home/venkat/Music/ /media/WALKMAN/MUSIC/
    To invoke this script whenever the device is plugged in, I added a udev rule.
    /etc/udev/85-walkman-sync.rules:
    Code:
    ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0404", RUN+="/usr/bin/walkman_sync_relay.sh"
    The thing with udev that I observed was that it runs the script after the device is plugged in before actually mounting the device. So udev runs a relay script that calls the acutal script and exits so, when the actual script that uses rsync is executed, the device is mounted in its place.

    walkman_sync_relay.sh:
    Code:
    #!/bin/bash
    /home/venkat/Desktop/scripts/devices/walkman_sync.sh & exit
    walkman_sync.sh
    Code:
    #!/bin/bash
    sleep 5
    rsync -avrh --progress --exclude-from=/home/venkat/Music/walkman_exclude /home/venkat/Music/ /media/WALKMAN/MUSIC/
    The syncing runs properly in the background when the device is plugged in. However, owing to the size of my music collection the process takes about 20mins.
    Now coming to the problem,
    MY QUESTION:
    1- Is it possible to modify the script to run the rsync command in an open terminal when the device is plugged in so that I can keep track of what files are being synced with the progress.
    Note: I tried the following but it didn't work.
    walkman_sync.sh:
    Code:
    #!/bin/bash
    sleep 5
    gnome-terminal -e rsync -avrh --progress --exclude-from=/home/venkat/Music/walkman_exclude /home/venkat/Music/ /media/WALKMAN/MUSIC/
    I don't think the rsync command was executed as the files didn't sync. I got this error message in the terminal:
    Failed to parse arguments: Unknown option -avrh

    I am a beginner at shell scripting, please do help me out on this one!

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    quoting

    Try it with quotes.

    Code:
    gnome-terminal -e "rsync -avrh --progress --exclude-from=/home/venkat/Music/walkman_exclude /home/venkat/Music/ /media/WALKMAN/MUSIC/"
    rsync, and all its options, needs to get passed to gnome-terminal as a single unit. Otherwise, it will act that -avrh, --progress, etc applies to it rather than to rync.

    Also, -avrh might be -avh instead. The -r is already part of -a.

  3. #3
    Join Date
    May 2014
    Beans
    8

    Re: Automated rsync shell script for syncing files

    Your solution works only when I run it manually.

  4. #4
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Automated rsync shell script for syncing files

    I don't think the udev environment is going to have any knowledge of your desktop session. At a minimum your script would need to set an appropriate DISPLAY variable - that may not be enough though.

    In general I try to avoid system processes that rely on a particular user's sessions or files being available. Since the device is being automounted in your desktop session via udisks, probably the right way to do it is via a udisks-glue post_mount_command (DISCLAIMER: I have never tried this!!)

    http://manpages.ubuntu.com/manpages/...ue.conf.5.html

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
  •