1

I wrote this small script to help me reduce the hassle involved in starting and stopping the lampp server on my local machine:

#!/bin/sh
#script to make lampp start/stop easier

if [ $1 == "start" ] ; then
    sudo /opt/lampp/lampp start &
elif [ $1 == "stop" ] ; then
    sudo /opt/lampp/lampp stop
else
    echo 'Wrong parameter.'
fi

I'd now like to go a step ahead and hardcode the superuser password into it so that I don't have to type it every time. I tried something like echo 'XXXX' | sudo /opt/lampp/lampp start & but got the three-unsuccessful-attempts error.

How can this be done?

5
  • It might be easier to add this script to sudoers with the nopasswd option, so you could just call the script as sudo myscript.sh. Commented Mar 28, 2014 at 19:24
  • I'd need to find out more about it, but doesn't that mean all the scripts that ever get created will have to be added to sudoers? God, I'm so lazy! :D Commented Mar 28, 2014 at 19:27
  • 1
    lazyness is good. you will make effectively writen (DRY) scripts... read the manual, anyway... Commented Mar 28, 2014 at 19:31
  • Here's another alternative - SetUI bit: askubuntu.com/a/167885/99884 Commented Mar 28, 2014 at 19:53
  • Add /opt/lampp/lampp to /etc/sudoers, not myscript.sh. Commented Mar 28, 2014 at 20:35

1 Answer 1

2

assuming your username is "dotslash":

sudo sh -c 'echo "dotslash ALL = NOPASSWD: /opt/lampp/lampp" > /etc/sudoers.d/dotslash'

Then you can

alias lampp='sudo /opt/lampp/lampp'
lampp start
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.