Pass parameter from Local to Sudo

Well, if the topic is not clear, I will explain my doubt. I have a shell script stored by my local user ( executeAdM.sh ), and when I execute this script I connect to the SUDO user by taking commands from the command file. But when I execute this script, I also pass in a parameter for this script, which is actually some path to the SUDO user directory. See below script -:

Script on 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

Doing the above like -:

./executeADM.sh somePath

script , SUDO, for, script, testADM.sh, script, script , Local User, testADM.sh , , prameter, . - , , . , , - , , LOCAL script SUDO USER shell script -:

SUDO script (testADM.sh) -:

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

script SUDO, . .:

 #!/bin/bash
 path=somepath
 cd $path
 pwd
+4

Source: https://habr.com/ru/post/1682939/


All Articles