Chris Charnegie
Chris Charnegie

Reputation: 39

Bash script working but fails in crontab

I am having issues with this script/cron. I am running on a Raspberry pi and I have other cronjobs working just fine(so I know its not cron on the system).

My script:

#!/bin/bash
rm -f /var/www/output/*

This script is working just fine in the command line bash clearcsv.sh but when I try to turn it in to a cronjob, it seems that it is not executing

Cron script: */6 * * * * /home/pi/clearcsv.sh

This should erase the contents of the "output" folder every 6 minutes, but it does not. If someone could tell me where I am failing or point me in the right direction that would be great

Thanks

total 160
drwxrwxrwx 14 pi   pi         4096 Mar 13 16:41 .

drwxr-xr-x  3 root root       4096 Dec 31  1969 ..

-rw-r--r--  1 pi   pi            0 Mar 10 21:56 ?

-rwxrwxrwx  1 pi   pi         8700 Mar 13 15:32 .bash_history

-rwxrwxrwx  1 pi   pi          220 Jan  7 16:10 .bash_logout

-rwxrwxrwx  1 pi   pi         3243 Jan  7 16:10 .bashrc

drwxrwxrwx  8 pi   pi         4096 Mar 10 19:24 .cache

-rwxrwxrwx  1 pi   pi           41 Mar 13 16:11 clearcsv.sh

drwxrwxrwx 12 pi   pi         4096 Feb 12 18:21 .config

-rwxrwxrwx  1 pi   pi          420 Mar 13 17:02 csv.sh

drwxrwxrwx  2 pi   pi         4096 Feb 12 18:20 Desktop

-rw-r--r--  1 pi   pi           35 Mar  7 08:17 .dmrc

drwxrwxrwx  2 pi   pi         4096 Jan 16 13:32 .fontconfig

drwxrwxrwx  2 pi   indiecity  4096 Jan 16 13:34 .gstreamer-0.10

drwxrwxrwx  2 pi   pi         4096 Jan 16 13:32 .gvfs

drwxrwxrwx  3 pi   pi         4096 Jan 16 13:33 indiecity

drwxrwxrwx  2 pi   pi         4096 Mar 13 13:27 input

drwxrwxrwx  3 pi   pi         4096 Jan 16 13:33 .local

drwxrwxrwx  9 pi   pi         4096 Jan 16 14:30 .Mathematica

-rwxrwxrwx  1 pi   pi         5781 Feb  3  2013 ocr_pi.png

-rwxrwxrwx  1 pi   pi            0 Mar 10 18:24 output.csv

-rwxrwxrwx  1 pi   pi          671 Mar 13 13:39 poller.sh
-rwxrwxrwx  1 pi   pi          117 Feb 19 17:34 poll.sh
-rwxrwxrwx  1 pi   pi          675 Jan  7 16:10 .profile


-rw-r--r--  1 root root          3 Jan 16 14:09 restart

drwx------  4 pi   pi         4096 Mar 13 13:22 .thumbnails

-rwxrwxrwx  1 pi   pi           56 Mar  7 08:17 .Xauthority

-rw-------  1 pi   pi        17227 Mar 13 16:56 .xsession-errors

-rwxrwxrwx  1 pi   pi         2385 Mar  6 19:06 .xsession-errors.old

Upvotes: 0

Views: 1278

Answers (1)

Chris Charnegie
Chris Charnegie

Reputation: 39

Thank you all for your help. I have everything working now! Here is the code if you are interested

New Script used:

#!/bin/bash /bin/rm -f /var/www/output/*

Cron */6 * * * * cd /home/pi && bash clearcsv.sh

Upvotes: 2

Related Questions