Inotify Unison Script

Discussion in 'Programming/Scripts' started by JoleG, Jan 6, 2016.

  1. JoleG

    JoleG New Member

    Hi Guys,

    I have a script to help me sync 2 file servers but my problem is its not working whenever I run it on startup like adding it on /etc/rc.local although I can see it running on process list. But if I run in on the shell it works. Please see my script below:
    #!/bin/bash
    inotifywait -mr -e close_write -e create -e delete -e move /folder | while read DELETE CREATE MOVE ; do unison ; done

    Thanks,
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Try to use the full path to inotifywait and if this does not help, try to send the process to the background.
     
  3. JoleG

    JoleG New Member

    You're a genius!! Why did that happen even if I specified the shell? Thanks alot Till!
     
  4. JoleG

    JoleG New Member

    Sorry Till I spoke too soon. It didnt work. :-(
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    Cronjobs and probably also rc scripts dont use the search pth, so paths to commands have to be defined as absolute path.

    Did you try to send this job to the background with:

    &> /dev/null

    at the end of the line in /etc/rc.local where you call your script?
     
  6. JoleG

    JoleG New Member

    But when I run it on schedule, like at, it works I wonder why its not working when added to startup.
     
  7. JoleG

    JoleG New Member

    I havent tried that yet. Should i add this on rc.local?

    /usr/bin/myscriptname &> /dev/null
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes.
     
  9. JoleG

    JoleG New Member

  10. till

    till Super Moderator Staff Member ISPConfig Developer

    Does it work as cronjob? Then you can e.g. start the script as 5 minute cronjob, extend the code in the script to check with ps if inotify is running, if it is not running, then start it, otherwise quit the script.
     
  11. JoleG

    JoleG New Member

    Yes thats what I ended up doing. Since I noticed it was running perfectly when using at, I made a script on cron to run it if its not. Still a mystery though. Thanks alot Till!
     
  12. mariaczi

    mariaczi New Member

Share This Page