Logo Background

Unix Directory Permission Checking Script

  • By on July 30, 2010 | 1 Comment

    Looking for shell script command to check Unix directory permission? Here’s the series of command to verify writing permission before running the Oracle SQL Loader (sqlldr).

    Every directory and file on the Unix system has an owner and also an associated group. It also has a set of permission flags which specify separate read, write and execute permissions for the ‘user’ (owner), ‘group’, and ‘other’ (everyone else with an account on the computer).

    Developer who code any loading program using shell script should include the logic to check on the Unix directory permission.

    This is to make sure the shell script has the permission to write into certain directory using Oracle SQL Loader (sqlldr).

    Include the shell script command logic as below to check the directory permission in the file pre-processing stage.

    #!/bin/bash
     
    #Check DATA directory to see if it exists or is not writable.
    if [ ! -w $CUSTOM_TOP/load/data/ ]
    then
        echo "Write permission is not granted to $CUSTOM_TOP/load/data"
        echo "Or directory does not exist"
        exit 1
    else
        echo "$CUSTOM_TOP/load/data exist"
    fi
    #Check ARCH directory to see if it exists or is not writable.
    if [ ! -w $CUSTOM_TOP/load/arch/ ]
    then
        echo "Write permission is not granted to $CUSTOM_TOP/load/arch"
        echo "Or directory does not exist"
        exit 1
    else
        echo "$CUSTOM_TOP/load/arch exist"
    fi
    #Check BAD directory to see if it exists or is not writable.
    if [ ! -w $CUSTOM_TOP/load/bad/ ]
    then
        echo "Write permission is not granted to $CUSTOM_TOP/load/bad"
        echo "Or directory does not exist"
        exit 1
    else
        echo "$CUSTOM_TOP/load/bad exist"
    fi
    Previous
    Next
    » Shell Script Check File Extension Plus Format
  1. #1 Jing Hong
    October 24, 2012 2:13 am

    You may use the command ‘find . -type d’ to list down all the directory recursively.

    Post ReplyPost Reply
Leave a Comment