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