User avatar
ScoobyDoo
Posts: 111
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK

Crontab help

Tue Apr 11, 2017 6:11 pm

Ive got the following bash script that runs fine with ./run.sh

Code: Select all

!/bin/bash

#/**
# * @file run.sh
# */

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

#backup the current working dir
WG_BCKP_DIR="$(pwd)"

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)) ;
else
    DUTDIR=$(dirname $0) ;
    if [ "${DUTDIR:0:1}" = "/" ]; then
        DIR="$DUTDIR";
    else
        DIR=$PWD/$(dirname $0) ;
    fi
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++/run.sh > /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?

User avatar
DougieLawson
Posts: 40818
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Crontab help

Tue Apr 11, 2017 6:14 pm

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.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Crontab help

Tue Apr 11, 2017 6:43 pm

Thought a bash script was suppose to start with a shebang.
Last edited by davef on Tue Apr 11, 2017 6:43 pm, edited 1 time in total.

User avatar
ScoobyDoo
Posts: 111
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK

Re: Crontab help

Tue Apr 11, 2017 6:43 pm

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?

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Crontab help

Tue Apr 11, 2017 6:57 pm

Code: Select all

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:
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.

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Crontab help

Tue Apr 11, 2017 8:46 pm

To answer your question:

Code: Select all

sudo find -name mono -print

User avatar
ScoobyDoo
Posts: 111
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK

Re: Crontab help

Tue Apr 11, 2017 8:53 pm

Excellent, thanks for your help. I'll look at sorting out the issue tomorrow.

User avatar
ScoobyDoo
Posts: 111
Joined: Wed Apr 04, 2012 2:52 pm
Location: Staffordshire, UK

Re: Crontab help

Fri Apr 14, 2017 10:16 am

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.

Return to “Beginners”