I'm trying to schedule this script to run every day by using crontb :

cd /home/banana/gdrive
DATE=`date +%Y-%m-%d`
mongodump  --gzip --archive=$DATE
./gdrive upload ./$DATE

olddate="$(date "+%Y-%m-%d" -d "9 days ago")"
old2=$(date -d $olddate +%s)
#echo $old2
list="$(./gdrive list)"
#echo $list
ADDR=(${list// / })
for i in "${ADDR[@]:5}"; do
    if [ $(($ii % 7)) -eq 0 ]; then
    if [ $(($ii % 7)) -eq 1 ]; then
       dat=$(date -d $name +%s)
       #echo $dat
       if [ $old2 -ge $dat ]; then
          echo "delete"
          echo $id
          touch $id
          ./gdrive delete $id
       #echo "name"
       #echo $name
       #echo $id
    #echo $ii
    #echo $i
    let ii=ii+1

crontab entry :

0 2 * * * /home/banana/gdrive/upload.sh

the script runs fine if lunched in a bash console, if it's run by crontab it doesn't reach the end even if i'm not able to find any logged error anywhere.

By simulating the use of the crontab environment as suggested here : https://serverfault.com/questions/85893/running-a-cron-job-manually-and-immediately/85906

i found out that the execution result in an error:

gdrive/upload.sh: 12: gdrive/upload.sh: Syntax error: "(" unexpected

given the fact that the SHELL variable in the crontab environment was set to SHELL=/bin/sh and that the syntax there is bash this sound quite reasonable (even if i'm still confusing on the role of the #/bin/bash on the first line of the script).

The problem is that the same outcome still even after putting SHELL=/bin/bash in the crontab file.

So the question is, what's wrong in this setup ? and how can i schedule this script by using crontab ?


The shebang that needs to be written includes an exclamation mark.

Try to write #!/bin/bash at the first line of your shell script.

  • yes, replacing #/bin/bash with #!/bin/bash solve the error – bn89 Oct 3 '16 at 10:49

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.