Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to launch a script bash from another one using sudo.

Here is my first script

echo "" $1 $2 $3  >>/home/pi/test.log
sudo ./ "$1" "$2" "$3" >>/home/pi/test.log &
echo " done!" >>/home/pi/test.log

When I run

./ a b c

in my console, it works. The second script is launched with args! But when the first script is launched from an other tools (Deluge Execute plugin), the second script is never launched. It looks like a problem with permissions.

Update : I rename the second script to and its make an echo in a second file


echo " Details: " $torrentid $torrentpath $torrentname >> /home/pi/temp.log

It works when launched by command line, but not by Deluge.

Update 2 : The second script is voluntary launch in a second shell/env with & because it will make a long action. I do this because when a script is launched & executed by deluge plugin, deluge is freezed during the execution. So I need a script that launches a second one in background.

Update 3 : my user pi as already pi ALL=(ALL) NOPASSWD: ALL in the visudo file

share|improve this question
Are you sure that Deluge Execute plugin sets the working directory correctly? Since you're referencing relatively to the working directory, it may not exist at all. – user2313067 Mar 30 '14 at 13:53
Both scripts are in the same folder. If I target from deluge, it's works. – RaspDealer Mar 30 '14 at 14:06
How do you conclude that doesn't run? Could you elaborate on that? Does the last statement, i.e. echo done execute? – devnull Mar 30 '14 at 14:18
The " done!" line will right now be written to the log directly after has forked; not when the command is actually done. You should rather have a second line like: (sudo ./ "$1" "$2" "$3" && echo " done!") >>/home/pi/test.log &. You still won't be able to provide credentials for sudo non-interactively, so you will need to give the Deluge user sudo privileges to execute without password authentication for your attempt to work. – Daniel Andersson Apr 28 '14 at 14:15
@RaspDealer: You can set such privileges in the sudo configuration file via the visudo command. Read up on the syntax. There might also be annotated examples and further instructions in the file when it opens. – Daniel Andersson Apr 28 '14 at 19:58

Try this:

cd "$(dirname "$0")"
# rest of script goes here
# ...
share|improve this answer
Whats does this line ? – RaspDealer Apr 28 '14 at 12:01
You explicitly invoke ./ -- you specify "find in the current directory". When you invoke, what is your current directory? Are you in the directory containing If not, you'll get an error like ./ command not found. If you (or deluge) calls "/home/raspdealer/bin/", then your current directory will change to "/home/raspdealer/bin", and then "./" will be found. – glenn jackman Apr 28 '14 at 15:07
Everything is in the same directory. – RaspDealer Apr 28 '14 at 17:41
That doesn’t matter, @RaspDealer. It’s all about the working directory. Never use relative paths when referring to “fixed” objects. – Daniel B Apr 30 '14 at 8:47

There are two problems with your BASH code:

  1. you use sudo which requires authentification, something Deluge Execute probably can't do (I don't know Deluge.)
  2. you use & which explicitly starts your command in a subshell with its own environment.

To fix 1. you have two options. You can either make the Deluge user a sudoer and echo the password into sudo like so echo $PASSWORD | sudo -S <command> or you can create an appropriate rule in your sudoers file to allow the Deluge user to run this command without authentication. Read the sudo man-page for more info.

To fix 2. just remove the "&" symbol and consider using the built-in command source. Read the BASH man-page for more info.

share|improve this answer

One definitive problem with

sudo ./ "$1" "$2" "$3" & >>/home/pi/test.log

is that you attempt to redirect the output after making the script run in background. Note that & acts as a command separator too, so you are essentially executing the following two commands:

sudo ./ "$1" "$2" "$3" &

You need to fix the order of the two. Say:

sudo ./ "$1" "$2" "$3" >>/home/pi/test.log &

Another problem is that you specify a relative path for the second script. Either replace ./ in the script with the absolute path or prefix it with the directory containing the script

"$(dirname "$0")"/
share|improve this answer
He could group all the commands with { ... } and redirect the output of the group. Or exec 1>logfile first. – glenn jackman Mar 30 '14 at 14:24
@glennjackman True. It's tough to read into the mind of the OP. I just pointed to an obvious problem that would cause the redirection to be a no-op that might lead one into thinking that the command isn't being executed. – devnull Mar 30 '14 at 14:25
Thanks for that but this problem matters without the & too... – RaspDealer Mar 30 '14 at 14:35
I've just update the post – RaspDealer Mar 30 '14 at 15:03
Problem persists ! – RaspDealer Apr 28 '14 at 17:45

Another issue is that two commands (sudo ./ "$1" "$2" "$3" and echo " done!") are writing to the same file (/home/pi/test.log) concurrently (i.e., simultaneously), because the (if it runs) has the file open in the background when the echo executes.  This shouldn’t be a major problem – it shouldn’t prevent from running – but if you do solve the primary problem and get to run, and it writes output, then it will probably overwrite the " done!" message.  Conversely, if runs quickly enough, then the echo could possibly overwrite the first 14 bytes of output from

share|improve this answer
I'm ok with that but my sure that ./ wille take few minutes. I just need to export this 'action' in an other script to release the first one. – RaspDealer Apr 28 '14 at 12:02

Try this Modified scripts.

cd "$(dirname "$0")"
echo " $1 $2 $3"  >>/home/pi/test.log
gksu bash ./ "$1" "$2" "$3" >> /home/pi/test.log &
echo " done!" >>/home/pi/test.log


echo "Details:  $torrentid $torrentpath $torrentname" >> /home/pi/temp.log

If gksu not available use pkexec


gksu is the graphical frontend of sudo. Just try sudo gedit and gksu gedit. Sudo removed from the newer version of Ubuntu. Did you tried the script ? How is it ?


try 1: add sleep 15 at the end of first script,
Try 2: add nohup before gksu. Ie nohup gksu bash ...

share|improve this answer
Whats does gksu bash and pkexec bach ? – RaspDealer Apr 28 '14 at 12:04
I've got this message "Refusing to render service to dead parents." when I launch it manually – RaspDealer Apr 28 '14 at 17:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .