Bash MKDIR automation script
by TBotNik from LinuxQuestions.org on (#4XA3S)
All,
Writing a svript to automate parst of the mkdir process:
Code:#! /bin/bash
# Script to set default permissions to a directory
downr="$USER:users"; # Assign Default users
dir=$1;
if [ -d "$dir" ] then
echo "Directory exists, only ownership and permissions will be changed!"
else
mkdir -P $dir
echo "directory $dir created!"
fi
chown -R $downr $dir;
defpm="775" # Set Directory permissions
dperm < ls -ld $dir
prm=$2;
if [ ] then
chmod -R $rwpms $dir;
fiI'm good to line 14 where I have the cmd:
Code:ls -ld directorwhich produces:
Code:drwxrwxr-x 35 $USER users 4096 Feb 16 2019 $dirWhat I need is the numeric permissions and the "owner:group" for my "IF" statements so I can make sure I have both the fight ownership and permissions comparing both the default value of $prm and $defpm to what the system says the permissions are.
I'm guessing I either need a different cmd other than ls -ld $dir or a way to process out the data it produces.
All help appreciated!
cheers!
TBNK


Writing a svript to automate parst of the mkdir process:
Code:#! /bin/bash
# Script to set default permissions to a directory
downr="$USER:users"; # Assign Default users
dir=$1;
if [ -d "$dir" ] then
echo "Directory exists, only ownership and permissions will be changed!"
else
mkdir -P $dir
echo "directory $dir created!"
fi
chown -R $downr $dir;
defpm="775" # Set Directory permissions
dperm < ls -ld $dir
prm=$2;
if [ ] then
chmod -R $rwpms $dir;
fiI'm good to line 14 where I have the cmd:
Code:ls -ld directorwhich produces:
Code:drwxrwxr-x 35 $USER users 4096 Feb 16 2019 $dirWhat I need is the numeric permissions and the "owner:group" for my "IF" statements so I can make sure I have both the fight ownership and permissions comparing both the default value of $prm and $defpm to what the system says the permissions are.
I'm guessing I either need a different cmd other than ls -ld $dir or a way to process out the data it produces.
All help appreciated!
cheers!
TBNK