Cron-->script-->script-->filebot fails

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Cron-->script-->script-->filebot fails

Post by noze2000 »

Hi all,

On my QNAP NAS (x86) I have constructed a bash script called rsync.sh which is called by crontab every hour and downloads media into various folders from my seedbox. It then calls another script filebot_bat.sh.

rsync.sh calls it with this line:

Code: Select all

/bin/sh /share/Disk1/filebot_bat.sh /share/Disk4/Download/lowresmovies /share/Disk8/lowresmovies >> /share/Disk1/filebot_call.log
Filebot_bat.sh looks like this:
(note that series always go to the same place - where sickrage picks it up later)

Code: Select all

#!/bin/bash
if [ ! -d "${1}" ]; then
    printf '%s: error: mandatory argument is not a valid directory.' "${0##*/}" 1>&2
    exit 1
fi

echo "$1 $2"
origindir="$1"
echo "$(date +"%T") \"from\" directory is: $origindir"

if [ ! -d "${2}" ];then echo "Unpack Directory is same dir"; unpackdir="$1";
	else 
		unpackdir="$2";echo "unpack dir is $unpackdir"
fi
seriesdir="/share/Download/sickrage"
echo "$(date +"%T") TV output dir is ${seriesdir}";

echo "$(date +"%T") Starting FILEBOT...."

/bin/sh /opt/bin/filebot -script fn:amc ${origindir} --log-file /share/Disk1/filebotnis_run.log --action move -non-strict --output srt "$origindir"  --def clean=y subtitles=en deleteAfterExtract=y -non-strict movieFormat="$unpackdir/{fn.length() > folder.name.length() ? fn.upperInitial().space('.').replaceAll(/\.Eng$/,'').replaceAll(/\.En$/,'').replaceAll(/\.en$/,'').replaceAll(/\.En$/,'') : folder.name.upperInitial().space('.')}/{fn.upperInitial().space('.')}" seriesFormat="${seriesdir} {fn.length() > folder.name.length() ? fn.upperInitial().space('.').replaceAll(/\.Eng$/,'').replaceAll(/\.En$/,'').replaceAll(/\.en$/,'').replaceAll(/\.En$/,'') : folder.name.upperInitial().space('.')}/{fn.upperInitial().space('.')}" 

echo "$(date +"%T") DONE FILEBOT"

When I run the rsync.sh script from terminal then everything works.
All files get unpacked and put in the right folders. Log files are created so I can follow the execution.

But when rsync.sh is executed by crontab, all downloads work and the logs shows that every line up til and after the filebot_bat.sh script is called. But the script simply does not execute. It does not even create the log file it is supposed to (/share/Disk1/filebotnis_run.log).

Am I doing something completely wrong here? what am I missing?
I changed filebot to /bin/sh /opt/bin/filebot

Code: Select all

[~] # which filebot
/opt/bin/filebot
[~] # 
but that didn't make any difference.

Thanks for any help.
This is killing my automation :o
I realize I'm noob in scripting - so I'm glad to learn.

//noze2000
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Re: Cron-->script-->script-->filebot fails

Post by noze2000 »

oh, and the log file tells me that Filebot starts and finishes is during the same second..

Code: Select all

 00:34:56 "from" directory is: /share/Disk4/Download/lowresmovies
unpack dir is /share/Disk8/lowresmovies
00:34:56 TV output dir is /share/Download/sickrage
00:34:56 Starting FILEBOT....
00:34:56 DONE FILEBOT
So maybe this is related to how arguments are passed?
Or it can't find filebot?
I have no way of knowing since that part of the "activity" is not in any of the logs I get..
User avatar
rednoah
The Source
Posts: 23930
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Cron-->script-->script-->filebot fails

Post by rednoah »

I donno. What does the output say? If you ignore the standard/error output of the FileBot command you probably won't find out why it's not working...

Please read this help page thoroughly:
viewtopic.php?f=4&t=3067
:idea: Please read the FAQ and How to Request Help.
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Re: Cron-->script-->script-->filebot fails

Post by noze2000 »

Excellent (love that you named that debug script for N00bs:)
Now the problem is clear..but I simply do not understand why this happens?
User calling this is admin (same as root on NAS)

output:
java-version.txt

Code: Select all

/share/Disk1/filebot_bat.sh: line 8: java: command not found
printenv.txt

Code: Select all

no output at all...
filebot-version.txt

Code: Select all

/share/Disk1/filebot_bat.sh: line 9: filebot: command not found
filebot-sysinfo.txt

Code: Select all

/share/Disk1/filebot_bat.sh: line 10: filebot: command not found
filebot-sysenv.txt

Code: Select all

/share/Disk1/filebot_bat.sh: line 11: filebot: command not found
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Re: Cron-->script-->script-->filebot fails

Post by noze2000 »

Code: Select all

[~] # which java
/usr/local/jre/bin/java
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Re: Cron-->script-->script-->filebot fails

Post by noze2000 »

I now tried to change

Code: Select all

# start filebot
java -Dunixfs=false -DuseExtendedFileAttributes=true -DuseCreationDate=false -Dfile.encoding="UTF-8" -Dsun.jnu.encoding="UTF-8" -Dapplication.deployment=ipkg -Dnet.filebot.Archive.extractor="$EXTRACTOR" -Dnet.filebot.AcoustID.fpcalc="fpcalc" -Dapplication.dir="$APP_DATA" -Djava.io.tmpdir="$APP_DATA/temp" -Duser.home="$APP_DATA" $JAVA_OPTS -jar "$APP_ROOT/FileBot.jar" "$@"
to

Code: Select all

# start filebot
/usr/local/jre/bin/java -Dunixfs=false -DuseExtendedFileAttributes=true -DuseCreationDate=false -Dfile.encoding="UTF-8" -Dsun.jnu.encoding="UTF-8" -Dapplication.deployment=ipkg -Dnet.filebot.Archive.extractor="$EXTRACTOR" -Dnet.filebot.AcoustID.fpcalc="fpcalc" -Dapplication.dir="$APP_DATA" -Djava.io.tmpdir="$APP_DATA/temp" -Duser.home="$APP_DATA" $JAVA_OPTS -jar "$APP_ROOT/FileBot.jar" "$@"
Didn't work. still cant find neither Java or filebot..strange.

Help?

Code: Select all

[/usr/local/jre/bin] # $PATH
-sh: /opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin:/Apps/bin:/Apps/sbin:/usr/local/jre/bin: No such file or directory
User avatar
rednoah
The Source
Posts: 23930
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Cron-->script-->script-->filebot fails

Post by rednoah »

filebot and java must be in the $PATH. If you call printenv from your shell and from cron you will see that it's different. When you log in via SSH your shell will execute ~/.profile and ~/.bashrc which will add paths like /usr/local/bin to the $PATH. If you call a script via cron, the user-specific login scripts are not called, thus the $PATH may be different.

You can easily fix this by adding the necessary paths to the system profile (e.g. /etc/profile) instead of your user profile.
:idea: Please read the FAQ and How to Request Help.
noze2000
Donor
Posts: 22
Joined: 08 Feb 2015, 20:08

Re: Cron-->script-->script-->filebot fails

Post by noze2000 »

I simply added the path to the script.
All done and all donated:)

Thanks!
Post Reply