Coder Social home page Coder Social logo

urethramancer / sentinel Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 16 KB

A simple, no-nonsense directory watcher tool for shell scripts.

License: MIT License

Go 90.45% Shell 9.55%
cli files monitoring fsnotify macos linux windows watch trigger golang

sentinel's Introduction

Sentinel Build Status

This command-line tool watches one or more directories for files being created, renamed, modified or deleted, then optionally runs a script. It uses the directory change APIs of Linux, macOS and Windows, respectively, thanks to the fsnotify package.

Dependencies

  1. Go version 1.7 or later.
  2. fsnotify
  3. go-flags

Build

Clone the repository and use "go build", and any ldflags etc. if you prefer. A task for Visual Studio Code is included.

Platforms

Tested on Linux and macOS. Should work on Windows without modification.

Usage

In its simplest use, Sentinel merely watches a directory until an expected type of change occurs, then returns:

sentinel -c /tmp

The above example waits for a file to be created in /tmp, then exits.

You can also tell it to run a simple shell script:

sentinel -c -C /usr/local/bin/watcher.sh /tmp

Or to keep running it again:

sentinel -c -C /usr/local/bin/watcher.sh /tmp -L

The specified script(s) will be given two environment variables, SENTINEL_ACTION and SENTINEL_PATH, to indicate what happened and to what.

The keyword in SENTINEL_ACTION will be create, write, delete, rename or chmod.

Any non-flag arguments found are taken as directories to watch, and any number you need is allowed. Multiple instances of Sentinel are required if you wish to run different scripts per folder.

Event flags

The supported types of events to watch for are as follows:

  • -c: Create. New files trigger this.
  • -w: Write. Triggered when an existing file is written to.
  • -d: Delete. Deleting a file from the watched directory will trigger this. Deleting the directory being watched has undetermined results (may vary per platform).
  • -r: Rename.
  • -m: Modification. Changing file permissions, date or attributes will trigger this.

Command parameters

Each event flag has a corresponding uppercase version to specify a script to run when triggered. The first argument passed to this script will be the name of the directory where something happened.

If you return exit code 1 from a script, Sentinel will quit even in loop mode.

Other flags

You can get a bit more output by passing the -v flag, or see the current version of Sentinel by passing -V.

Licence

MIT.

sentinel's People

Contributors

urethramancer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.