Linux – How to launch a bash script in another one

bashlinuxraspberry pi

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

Here is my first script
test.sh

#!/bin/bash
echo "test.sh" $1 $2 $3  >>/home/pi/test.log
sudo ./temp.sh "$1" "$2" "$3" >>/home/pi/test.log &
echo "test.sh done!" >>/home/pi/test.log

When I run

./test.sh 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 temp.sh and its make an echo in a second file

#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3

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

Best Answer

Try this:

#!/bin/bash
cd "$(dirname "$0")"
# rest of script goes here
# ...