-1

I have a shell script that uses a mapfile command.

#!/bin/sh

mapfile all_lines < "/var/www/weewx/temp.txt"

a="${all_lines[1]}"
b="${all_lines[3]}"

If i run the shell script from the command line as in:

./overlay.sh

it runs without error.

if however I run it from crontab I get the following error:

/home/pi/WeatherCam/overlay.sh: 10: /home/pi/WeatherCam/overlay.sh: mapfile: not found

Can anyone explain why this occurs and how to fix it? Thanks for and and all help!!!

EDIT: from another forum it was suggested I change it to a bash script (#!/bin/bash) and that solved the problem... it now runs without error from crontab. The strange thing is when I ran $ which mapfile nothing is returned? (see answer below) all quite confusing!

4

When run under cron, your environment is not passed in, so within your script, you often need to specify the full path to binaries. For example:

#!/bin/sh

/usr/local/bin/mapfile all_lines < "/var/www/weewx/temp.txt"

a="${all_lines[1]}"
b="${all_lines[3]}"

You'll need to find what the real path is. which mapfile may be of help.

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.