Pass parameter from Local to Sudo user

Viewed 1422

Ok if subject is not clear i will explain my doubt.I have a shell script kept at my local user called (executeAdM.sh), and when i execute this script i am connecting to SUDO user by taking commands from instruction file.But when i execute this script i am also passing parameter to this script which is actually some directory path of SUDO user. See the script below-:

Script at local(executeADM.sh) -:

#!/bin/bash
echo password | sudo -S -l
sudo /usr/bin/su - user  <<\EOF
#ls -lrt
pwd
for entry in $(ls -r)
  do
  if [ "$entry" = "testingADM.sh" ];then
./$entry $1
fi
done
EOF

Executing Above as-:

./executeADM.sh somePath

When above script executes it connects successfully to another user, and at SUDO user i execute a for loop which search for another SCRIPT called testingADM.sh . Once the script is found i execute that script with parameter passed from Local User and testingADM.sh should set that path for me which is not working it is not reading prameter passed from local user.Can anyone help me here i am not getting how to solve this. Please ask me if anything is not clear basically i want to pass parameter from LOCAL shell script to SUDO USER shell script-:

SUDO user script (testingADM.sh)-:

#!/bin/bash
path=$1
cd $path
pwd

If i hard code path variable value in script kept at SUDO all works fine . But i don't want that.:

 #!/bin/bash
 path=somepath
 cd $path
 pwd
0 Answers
Related