-1

The script is for adding torrent files to a folder and having them added to transmission. Here's the script:

#!/bin/bash
for file in /home/me/box/*/*
do
dir=$(basename $(dirname "$file"));
sudo chmod 0777 /var/log/torrentwatch.log
sudo chmod -R 0777 /home/me/box/*/*
if "$file" = "/home/me/box/*/*.torrent"; then
echo [`date`] "$file" added to queue. >> /var/log/torrentwatch.log
/usr/bin/transmission-remote localhost:9091 --auth=transmission:transmission -l -w /media/Media/Torrents/$dir -a "$file"
sleep 40 && rm "$file"
sleep 3 && sudo chmod -R 777 /media/Media && sudo chown -R debian-transmission:debian-transmission /media/Media/info
fi
done

The problem is that when I run the script I get

/home/me/box/TV/Name.of.file.torrent: Syntax error: "(" unexpected

I've tried running the script with bash, sh, and zsh, and none seem to work. I can't figure out what the problem is.

0

There are several issues from what I see in your script.

Try the following. Replace

dir=$(basename $(dirname "$file"));

With

dir=$(basename "$(dirname "$file")");

This should resolve your error, however, there are other few things I recommend:

echo [`date`] "$file" added to queue. >> /var/log/torrentwatch.log

I would change that to

 echo "[$(date)]" "$file" added to queue. >> /var/log/torrentwatch.log

This would prevent few issues, among them word splitting, and the somewhat dangerous and not portable use of `.

/usr/bin/transmission-remote localhost:9091 --auth=transmission:transmission -l -w /media/Media/Torrents/$dir -a "$file"

I would change that to:

/usr/bin/transmission-remote localhost:9091 --auth=transmission:transmission -l -w /media/Media/Torrents/"$dir" -a "$file"

This would prevent globbing and word splitting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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