Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created January 10, 2020 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/46d8ed3ee478572a7dad1e138fb09d4a to your computer and use it in GitHub Desktop.
Save nickanderson/46d8ed3ee478572a7dad1e138fb09d4a to your computer and use it in GitHub Desktop.
Automaticly clean up unexpected things
mkdir -p /tmp/automatic-cleanup/ 
touch /tmp/automatic-cleanup/want-1
touch /tmp/automatic-cleanup/need-2
touch /tmp/automatic-cleanup/expect-3
touch /tmp/automatic-cleanup/extra-1
touch /tmp/automatic-cleanup/delete-me-2
bundle agent main
{
  vars:
      "expected" slist => { "want-1", "need-2", "expect-3" };

      "found" slist => lsdir( "/tmp/automatic-cleanup/", "^(?!(\.$|\.\.$)).*", false);

      # Note, order of found vs expected is important
      "unexpected" slist => difference( found, expected);

  reports:
      "$(unexpected)";
}
R: extra-1
R: delete-me-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment