2
2
i have a script
#!/bin/sh
# Automatically remove a torrent and delete its data after a specified period of
# time (in seconds).
TARGET=/var/www/transmission/completed
USER=name
PASS=pass
BIN="/usr/bin/transmission-remote"
# The default is 5 minutes (in seconds).
CUTOFF=`expr 100 \* 3`
##############################################
### You shouldn't need to edit below here. ###
##############################################
# Tokenise over newlines instead of spaces.
OLDIFS=$IFS
IFS="
"
for ENTRY in `$BIN -n $USER:$PASS -l | grep 100%.*Done.*Finished`; do
# Pull the ID out of the listing.
ID=`echo $ENTRY | sed "s/^ *//g" | sed "s/ *100%.*//g"`
# Determine the name of the downloaded file/folder.
NAME=`$BIN -n $USER:$PASS -t $ID -f | head -1 |\
sed "s/ ([0-9]\+ files)://g"`
# If it's a folder, find the last modified file and its modification time.
if [ -d "$TARGET/$NAME" ]; then
LASTMODIFIED=0
for FILE in `find $TARGET/$NAME`; do
AGE=`stat "$FILE" -c%Y`
if [ $AGE -gt $LASTMODIFIED ]; then
LASTMODIFIED=$AGE
fi
done
# Otherwise, just get the modified time.
else
LASTMODIFIED=`stat "$TARGET/$NAME" -c%Y`
fi
TIME=`date +%s`
DIFF=`expr $TIME - $LASTMODIFIED`
# Remove the torrent if its older than the CUTOFF.
if [ $DIFF -gt $CUTOFF ]; then
date
echo "Removing $NAME with ID:$ID"
$BIN -n $USER:$PASS -t $ID --remove-and-delete
fi
done
IFS=$OLDIFS
but when i try to run it i get this error: /root/transmission_r.sh: 1: /root/transmission_r.sh: #!/bin/sh: not found
...so, what does
ls /bin/sh
give you? – Arjan – 2015-08-01T11:14:12.560it gives me: /bin/sh – Nojus741 – 2015-08-01T11:18:59.647
1Any funny characters on that first line then? – Arjan – 2015-08-01T11:21:08.830
http://i.imgur.com/V6V4OJw.png – Nojus741 – 2015-08-01T11:22:25.920
4Ahh, got it, file encoding was set to UTF-8, i set it to without BOM and it works now. – Nojus741 – 2015-08-01T11:23:32.503
Also, line endings might fool you. – Arjan – 2015-08-01T11:24:36.107