I need to create a folder in the current directoy of the shell script im executing. This piece of code work very well when I execute the script myself but when it get executed by crontab, it always create the folder in the top layer of the user profile.
#Where $log_folder is a certain path
if [ ! -d "$log_folder" ]; then
mkdir -m a=rwx $log_folder
fi
So if I execute the script from the following path: /export/home/nz/tmp/test/GenerateScript.sh , the folder will be created in /export/home/nz/ (Where nz is my user) instead of being in /export/home/nz/tmp/test/.
Is there another option I need to add to mkdir or is it something I need to add to crontab? I already linked the user profile in crontab with the following:
$HOME/.bash_profile
Thank you.
EDIT:
Ive been able to do what I wanted by adding those 2 line just before creating the folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
If there is a better way, feel free to show me!