Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have found an error in monit init script that I want to fix on my own for now. The faulty code is

PID_DIR=$(/bin/basename "$MONIT_PID_FILE")
/bin/mkdir -p -m0700 "$PID_DIR"

The developer wants to create the directory /var/run/monit from $MONIT_PID_FILE that equals to /var/run/monit/monit.pid, but unfortunately basename returns the file name, not directory path. This causes the directory not being created and monit not starting.

How can I get a file's directory full path starting from the file's full path? ie. /usr/local/myfile.f => /usr/local

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Use dirname to get the directory path (instead of using basename).

Refer: dirname

share|improve this answer
add comment

Your Answer

 
discard

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.