Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm an avid torrenter, and since I'm busy must of the day, having Transmission-GTK run at night is my best option. However, my college server loves to kick people out after either an extended time limit or a download limit on wifi. I needed automation while I was sleeping.

Using Java-GTK and Bash, created a application that brings up a window asking for which VPN to use. It stores the output in a variable and connects it. Then, if the connection was a success it started up transmission.

Now, Ive set up a script that pings 8.8.8.8 every hour on the hour, if it failed, it pings my school network. If that failed kills transmission, then it restarts the network using sudo service network-manager restart. Then reconnects the VPN, and finally restarts transmission. (I know that I can use stop / start but I choose not to). Upon usage, I face-palmed and realized that sudo needed my password as the admin.

I've researched this for nearly a week, looking for some way to give a script root privileges, and I have seen hundreds of warnings and "sudo is the way" comments. I've looked into the sudoers file, tried it, and it hasn't worked (it still prompts for a password for the most basic configurations). I've also looked into creating a C binary telling a script to run with 0 uid, setting that C binary to chmod and chown root permissions. To no avail. (I have not tried daemons as I know very little of C.) (Mostly Bash, and a bit of Java).

Perhaps a script/configuration in /etc/network folder? I don't mind answers that work outside of my original script framework, as security precautions prevent scripts from being rooted.

PS. I'm not looking for warnings as answers, but answers with warnings.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

sudo is the way

Have you considered running the script itself under sudo?

sudo sh .\myScript

If you add the script to the userlevel (rc stuff), I think it would also run with root privileges.

share|improve this answer
    
hmmm. I did not... I tried gksudo with it, and it works. So I may keep that, if I don't see a cleaner solution. Also, I had considered rc, but it usually looked far too technical for a 20 minute introduction. ;) Thanks! –  new.KID.ontheBLOCK Apr 6 '12 at 8:30
    
Most create rc script tutorials I can find only require you to read for like 1 -2 minutes, after which you can just copy paste the code and execute the commands. rc is the proper solution, I don't think there are other cleaner solutions. What distribution are you running? –  Tom Wijsman Apr 6 '12 at 8:48
    
Ubuntu (currently debating between Mint and Debian testing). I'll definitely look into rc tomorrow –  new.KID.ontheBLOCK Apr 6 '12 at 8:54
1  
.\myscript - I sense a disturbing Windows presence... ;-) –  Daniel Andersson Apr 6 '12 at 10:07
1  
I created a test script restarting my network five times over 35 minutes. I started the script within a parent script with root privileges with gksudo ./tester2. And it worked! (I'll try rc if I run into problems later on with rooting scripts). Thanks for the help! –  new.KID.ontheBLOCK Apr 6 '12 at 20:19
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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