当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Exec script as root in autostart

问题描述:

I need to launch a log on script. This log on script contain several commands like : *cp, ln, and chown.*

But "chown" need to be root to be efficient. So my script is doing well, except the "chown" command.

My environnement :

Debian Jessie, LXDE.

My script (in /usr/local/bin/transfertPOL.sh) :

 #!/bin/bash

#transfert de POL au démarrage de la session

groupe=$(id -gn $1)

uid=$(id -u $1)

POL=/var/POL

home=$(eval echo ~$1)

lien=$home/.PlayOnLinux

#changement de propriétaire du dossier

sudo chown -h -R $1:$groupe $POL

ln -s $POL $lien

sudo chown -h -R $1:$groupe $lien

#Copie des raccourcis sur le Bureau

cp --preserve=ownership $POL/shorcuts/*.desktop $home/Desktop

My Desktop Entry in /etc/xdg/autostart/transfertPOL.desktop :

 [Desktop Entry]

Type=Application

Exec=sh /usr/local/bin/transfertPOL.sh

The Exec, I tried several things :

 Exec=sh /usr/local/bin/transfertPOL.sh #Work, but the chown don't

Exec=/bin/bash/ -c "sudo /usr/local/bin/transfertPOL.sh" #doesn't work

Exec=sudo sh /usr/local/bin/transfertPOL.sh #Work, but the chown don't

For this one, I've created a /etc/sudoers.d/transfert with

%users ALL=NOPASSWD: /usr/local/bin/transfertPOL.sh

The script is a symbolic link to PlayOnLinux local folder. Each users need to access to this specific POL folder. So when a user is logging, the chown is changing folder rights.

Do you have any idea to help me ?

Thanks

网友答案:

You are calling sh in the Exec command:

Exec=sudo sh /usr/local/bin/transfertPOL.sh

So the sudoers entry:

%users ALL=NOPASSWD: /usr/local/bin/transfertPOL.sh

wont run with root privileges.

You probably want to make your script executable:

sudo chmod +x /usr/local/bin/transfertPOL.sh

And change the Exec command to:

Exec=sudo /usr/local/bin/transfertPOL.sh

BUT: We got groups for that in Linux, try setting the correct group permissions on the files you want to read/write. You wont need that script at all then.

分享给朋友:
您可能感兴趣的文章:
随机阅读: