Score:0

Running a bash script in crontab fails

cn flag

I have two scripts that work perfectly from the command line but don't work in crontab. The scripts are for requesting a GRIB weather file via email.

The script looks in the email out box folder for an existing request and deletes it if it exists. It then gets GPS data and makes the new request based on the GPS location at the time of the request. A new request is generated and put in the out box folder.

Here is one of the scripts:

#! /bin/bash

# checking for existing requests
R=$(grep -l  "Grib" /user/.wl2k/mailbox/email-user/out/*.b2f)
if [ -n "$R" ]
then
rm $R
fi

#get GPS cordinates Lat/Lon
 X=$(gpspipe -w -n 10 |grep lat|tail -n1|cut -d":" -f9|cut -d"," -f1)
 Y=$(gpspipe -w -n 10 |grep lon|tail -n1|cut -d":" -f10|cut -d"," -f1)

# adding + or - 25 to longitude, and + or -12 to latitude
 A=$(echo "scale=4; $X+12" | bc -l)
 B=$(echo "scale=4; $X-12" | bc -l)
 C=$(echo "scale=4; $Y-25" | bc -l)
 D=$(echo "scale=4; $Y+25" | bc -l)

# Sending the GRIB request to pat (this is for weather)
curl http://localhost:8080/api/mailbox/out -F "date=$(date -u +'%Y-%m-%dT%H:%M:>
|2,2|6,12..96|PRESS,WIND,GUST,=
CAPE,RAIN,CLOUDS,AIRTMP,WAVES"
muru avatar
us flag
What does "don't work" mean? Have you tried logging in the crontab? `/some/script > /some/log/file 2>&1` and `set -x` in the script?
Artur Meinild avatar
vn flag
Please provide some more info. Where are the scripts located, and please post your crontab contents where the scripts are run from. It's usually because of a broken `PATH`. Also as muru states, what happens if you log the output - do they run at all or not?
Wayne Vosberg avatar
bd flag
Possibly a PATH issue - try adding full paths to your executables or making sure PATH is complete first thing in the script.
FedKad avatar
cn flag
Also correct the first line by removing the space character between `#!` and `/bin/bash`.
hr flag
@FedonKadifeli that appears to be a myth - see for example [Is space allowed between #! and /bin/bash in shebang?](https://unix.stackexchange.com/questions/276751/is-space-allowed-between-and-bin-bash-in-shebang)
FedKad avatar
cn flag
Didn't know that @steeldriver. Thank you for warning me!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.