Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In the monit documentation I can see there is a check directory command but I can't see any examples of how to use it to see if the directory exists and if it doesn't to create the directory using the mkdir command.

share|improve this question

3 Answers 3

This works for me:

check directory my_path path /mnt/some_mount_point
  if does not exist then exec "/usr/local/bin/create_mnt.sh"
share|improve this answer

This might help you mkdir -p $directory should do what you want. The -p option will create any necessary parent directories. If $directory already exists as a directory, the command does nothing, and succeeds. If $directory is a regular file, it will remain untouched, nd does not fail if the directory already exists, so you can do it all at once with:

mkdir -p /some/directory/you/want/to/exist || exit 1

share|improve this answer

Alec pretty much has it, but you don't need to create a script to do this. You can run mkdir directly (though note you need the full path to it):

check directory my_path path /mnt/some_mount_point
  if does not exist then exec "/bin/mkdir /mnt/some_mount_point"

Depending on your path, it may help to add the -p switch to mkdir if you need subfolders and/or duplicate error suppression.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.