1

I have looked everywhere for a solution that lets me run CIFS automount script after login with around 20 second delay. What I have tried. Added the script to visudo:

rait ALL=(ALL) NOPASSWD: /home/rait/Downloads/Testing/mount.sh, /bin/mount

After that added the script to Startup applications, but it does not work. Also I tried adding it to .bash_profile and rc.d. In rc.d it works but that does not run it after login. I need it after login because it will ask people for their AD user and password via GUI. The script itself looks like this:

    #!/bin/bash
MOUNTDIR=Public
DIRNAME=Avalik
DOMAIN=Domain
SERVER=server_adr
SHARE=shares

if [ ! -d ${HOME}/Documents/${DIRNAME} ]; then
    mkdir ${HOME}/Documents/${DIRNAME}
fi

# get the windows username
wUsername=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Kasutaja
nimi:"`
if [ $? -ne 0 ]; then
    exit 1
fi

# get the windows password
wPassword=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Parool:"
 --hide-text`
if [ $? -ne 0 ]; then
    exit 1
fi

mount -t cifs //$SERVER/$SHARE ${HOME}/Documents/${DIRNAME} -o username=${wUsern
ame},password=${wPassword},domain=${DOMAIN}

if [ $? -eq 0 ]; then
    zenity --info --title="Mount OK!" --text="Mount OK!"
else
    zenity --error --title="Mount Failed!" --text="Mount Failed!"
fi

I hope that someone knows how to do it.

PS: After I edited the visudo now it asks for root password after I open terminal. So terminal asks me for sudo password when ever I open it after login. Once I remove the line that should run the script in visudo it does not ask for password anymore.

Please help :)

0

I don't know if this is a solution for your problem, but you could try to use the setuid flag. To do so, make your script owned by root (chown root:root <filename>) and then chmod +s <filename> it.

Of course you have to be careful which programs you make setuid root, since if the program has a security flaw so its users can make it run arbitrary code, it might be misused to gain full root access.

Regarding the automatic start after login, I think that indeed "Startup Applications" is the place to put it.

  • The script has root ownership and I do not want setuid to be honest. I just want it to run in sudo after login and nothing else. The script is in Startup Applications and the command to run it is bash /script/dir/ – mYzk May 14 '14 at 12:14
  • I even tested ~/.profile but nothing is opening up. The password promt wont open up or anything. – mYzk May 14 '14 at 13:35
  • Fixed it by adding this to sudoers: %sudo ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount And the Startup Applications command was edited so it was /home/user/script/path/script.sh and it started to work. Also added sudo infront of the mount command in the script as well. :) Thanks for you help guys :) – mYzk May 14 '14 at 14:17
0

Fixed it by adding this to sudoers:

%sudo   ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount

And the Startup Applications command was edited so it was /home/user/script/path/script.sh and it started to work. Also added sudo infront of the mount command in the script as well.

Thanks for you help guys :)

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.