Problem with running a script at startup as root?

Posted by Usman Ajmal on Super User See other posts from Super User or by Usman Ajmal
Published on 2010-04-14T09:17:24Z Indexed on 2010/04/15 12:33 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

Hi

The main question:

Is there a way I can run 'completely' one of my script when ubuntu's desktop appears no matter if root , administrator, desktop user or an unprivileged user logged in?

What does the script do?

The script mounts a partition, looks for a file in that partition and finally on the basis of that file a decision of copying a partition to another partition is made. That copying is done via

dd if=/dev/sda2 of=/dev/sda5

When does the script run finely?

Script runs smoothly when I run it from the terminal by

sudo ./my_copying_script

This command asks me for the password of currently logged in user. I enter the password and the script starts working.

When does the script NOT run finely?

I want to run the script at startup. I set it a startup program by using the Startup Applications utility of Ubuntu. Script ran at startup but exited at the dd command returing following error:

dd: opening '/dev/sda2': Permission denied 

On edk's suggestion I set the owner of my_copying_script as root and set the SUID. Now the permissions of my_copying_script are (-rwsr-sr-x). edk's point of view was that once I set the suid, the startup program will run with the permissions of its owner. I did that but the same /dev/sda2 permission denied error came up.

I then prefixed the dd with sudo as mentioned below

 sudo dd if=/dev/sda2 of=/dev/sda5

but this returned following error:

sudo: no tty present and no askpass program specified

In other words the mounting failed. If I run the script using sudo ./myProgram i don't face this problem and the drive gets mounted successfully.

© Super User or respective owner

Related posts about linux

Related posts about sudo