PDA

View Full Version : [SOLVED] How to run sudo command inside bash script? (when a daemon is calling the script)



RicardoEscobar
July 6th, 2012, 04:59 AM
Hello there. Here is the situation:

I installed a twitter client calles "Twidge" so my ubuntu server can tweet now (cool)

To tweet:


sudo twidge update "This is a test tweet"If I run it without sudo:


twidge update"This is a test tweet"
twidge: /home/user/.twidgerc: openFile: permission denied (Permission denied)On the other hand I have an script called tuitTorrent.sh, and here it is:


#!/bin/bash
#Este script se ejecuta desde /var/lib/transmission-daemon/info/settings.json
sudo twidge update "@MyTwitterAccount torrent downloaded.`date`"If I run the scrip as


sudo /home/user/scripts/tuitTorrent.**** ask for my sudo password and I just type it in, then it works.

However I installed Transmission, a bit torrent client, on the configuration file: var/lib/transmission-daemon/info/settings.json I may set up the path to a script with runs after the torrent downloads successfully. So I set this on the configuration file:


"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/home/user/scripts/tuitTorrent.sh",However when a torrent finishes downloading, the script never runs, I guess it's because the twidge command requires a sudo prefix, and I don't know how to give an script sudo execute level or how to enable twidge to run without needing a sudo password.

So there is my problem, I want to tweet after transmission finishes to download, I have the script but it does not run unless it have a sudo password, yet I don't execute the script directly, transmission daemon runs it.

markbl
July 6th, 2012, 06:19 AM
You are going about "fixing" this problem the wrong way.

It seems you originally mistakenly configured twidge as root, not yourself. Just sudo rm ~/.twidgerc and then configure twidge properly i.e. run twidge setup as yourself.

RicardoEscobar
July 6th, 2012, 04:21 PM
You are going about "fixing" this problem the wrong way.

It seems you originally mistakenly configured twidge as root, not yourself. Just sudo rm ~/.twidgerc and then configure twidge properly i.e. run twidge setup as yourself.

Ok, I'm gonna try that.

RicardoEscobar
July 6th, 2012, 04:28 PM
Thanks a lot markbl, I finally did it.

Now I may tweet using my user (no sudo prefix) and transmission may tweet too, I can use tweets inside scripts too, thanks.:KS