[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Unable to execute a script without asking for sudo password, even after editing sudoers file.



Hi I have created a script called i3exit that allows me to suspend or
hibernate my laptop without having to exit my i3wm thus allowing me to
save my  work.

Here are the contents of my script:

#!/bin/sh
lock() {
    i3lock
}

case "$1" in
    lock)
        i3lock -d -i /home/neo1691/.i3/i3lock_screen.png -n
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        sudo pm-suspend
        ;;
    hibernate)
        sudo pm-hibernate
        ;;
    reboot)
        sudo reboot
        ;;
    shutdown)
        sudo halt
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0

This script is stored in home/neo1691/bin/ directory and the directory
is added in the PATH variable by adding   'export
PATH=${PATH}:/home/neo1691/bin' in my .~/.bashrc file

I used sudo visudo to edit the /etc/sudoers file and added this line at the end:
 neo1691 ALL=(ALL) ALL, NOPASSWD: /home/neo1691/bin/i3exit

After a restart when I run 'i3exit suspend' from my terminal, I am
still asked for my password.

To sum it up here are the problems that I want to solve:
1) How can I run the script without asking for a password?
2) Is exporting the PATH variable like I had did is the correct way to
add my directory to PATH, if I want the other processes to also access
the scripts in
that folder?

Thanks!

-- 
Regards,
Anubhav Yadav
Imperial College of Engineering and Research,
Pune.


Reply to: