Page 1 of 1

Crontab help

Posted: Tue Apr 11, 2017 6:11 pm
by ScoobyDoo
Ive got the following bash script that runs fine with ./

Code: Select all


# * @file
# */

# remove guide.xml
cd /home/pi/wg++
rm guide.xml

#backup the current working dir

function quit {
    #restore previous working dir
    cd "$WG_BCKP_DIR"
    exit $1;

# check if mono can be found
which mono >/dev/null 2>&1 || { echo >&2 "Mono required, but it's not installed."; quit 1; }

# get the absolute path of the link (or relative path)
if [ -L $0 ] ; then
    DIR=$(dirname $(readlink -f $0)) ;
    DUTDIR=$(dirname $0) ;
    if [ "${DUTDIR:0:1}" = "/" ]; then
        DIR=$PWD/$(dirname $0) ;
fi ;

mono "$DIR/bin/WebGrab+Plus.exe" "$DIR"

Im trying to get this to run via a crontab on certain days.
My crontab ran under 'root' is
0 2 * * 1,3,5,7 /home/pi/wg++/ > /home/pi/wg++/backup.log 2>&1

The crontab runs fine when it should at the correct time,day etc but the bash script doesnt execute correctly. I get an error saying 'Mono required, but it's not installed'. It seems like when its ran through crontab it doesnt think mono is installed on the pi.

Any ideas please?

Re: Crontab help

Posted: Tue Apr 11, 2017 6:14 pm
by DougieLawson
Does the PATH= variable in your cron environment include the directory where mono is installed? If not then change "mono" to be "/dir/subdir/subsubdir/mono" with the fully qualified name of your mono executable.

Re: Crontab help

Posted: Tue Apr 11, 2017 6:43 pm
by davef
Thought a bash script was suppose to start with a shebang.

Re: Crontab help

Posted: Tue Apr 11, 2017 6:43 pm
by ScoobyDoo
Thanks for your reply.

I'm still doing the basics at the moment, do you know how i can find out what the path is for the mono executable?

Re: Crontab help

Posted: Tue Apr 11, 2017 6:57 pm
by davef

Code: Select all


and add a path to your mono following this format

Also you can tweak your environment variables.
Do printenv on the command line. I forget how it is edited then do a saveenv

I recall the process is:
- stop the boot process
- printenv
- type in the new PATH line, try not to make any mistakes
- saveenv
- reboot

Placing the PATH line in your Bash Script will be easier.

Re: Crontab help

Posted: Tue Apr 11, 2017 8:46 pm
by davef
To answer your question:

Code: Select all

sudo find -name mono -print

Re: Crontab help

Posted: Tue Apr 11, 2017 8:53 pm
by ScoobyDoo
Excellent, thanks for your help. I'll look at sorting out the issue tomorrow.

Re: Crontab help

Posted: Fri Apr 14, 2017 10:16 am
by ScoobyDoo
Just a thank you for helping sorting out the issue.

The crontab is working great now with the relative path to mono inserted into the bash script.