Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using sudo in an if condition 1

Status
Not open for further replies.

philipose

Programmer
Dec 24, 2003
137
US
Hi Gurus,
Does anyone know to use a sudo in an if condition ? Can you tell me if the first one will work or the second one. What happens if there are multiple lines in the if condition ??
Thanks a lot

sudo -u auser if [[ ! -d "mappedfolder/subfolder" ]]; then
sudo -u auser echo "mappedfolder is not mapped for user"
sudo -u auser fi

sudo -u auser if [[ ! -d "mappedfolder/subfolder" ]]; then
echo "mappedfolder is not mapped for user"
fi
 
or should it be

if [[ sudo -u auser ! -d "mappedfolder/subfolder" ]]; then
echo "mappedfolder is not mapped for user"
fi
 
sudo can only launch commands, not shell tests or scraps of code. This is for security purposes.

You'll need two scripts to do what you want:

Code:
# script1

if [[ ! -d "mappedfolder/subfolder" ]]
then
   echo "mapped folder is not mapped for user"
fi

Code:
# script2

sudo -u auser /full/path/to/script1

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top