I have some concerns regarding the script below which creates folder per line from file. Folder.list is located in /scripts/ . 1st script works smoothly but the 2nd script doesn't work when trying to switch to different user.
-- 1st script--
#!/bin/ksh
while read line
do
if [ ! -d $line ]
then
mkdir -p $line >/dev/null 2>&1 && echo "Directory $line created."
else
echo "Error: $line directory exists!"
fi
done < folder.list
--2nd script--
#!/bin/ksh
#Switch user
export SUDO_ASKPASS=/keys/askpass.sh
sudo -A su - appuser<<EOF
#Go to folder.list directory
cd /scripts/
while read line
do
if [ ! -d $line ]
then
mkdir -p $line >/dev/null 2>&1 && echo "Directory $line created."
else
echo "Error: $line directory exists!"
fi
done < folder.list
EOF
$lineshould be escaped to\$line?;rm -rf /and see what happens.xargs mkdir -vp <folder.list?