Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I manually type:

root@username:~# ./myscript.sh

the script executes, however I tried the following combinations to have crontab execute myscript.sh every 30 minutes (forever) and none seem to do anything:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
*/30 * * * * root sh /root/myscript.sh
*/30 * * * * root sh ./myscript.sh
*/30 * * * * root sh myscript.sh
*/30 * * * * root ./myscript.sh 

Contents of myscript.sh:

KEYWORDS=("Word1" "Word2" "Word3" "Word4")
IFS=$'\n'
find . -size +1c -type f ! -exec grep -qwF "${KEYWORDS[*]}" {} \; -exec truncate -s 0 {} \;
share|improve this question
1  
Please post your script, also try adding 2> logfile to your cron line so you can capture any errors. –  terdon Jan 17 at 16:33
    
# cat /var/log/cron | grep myscript.sh Any errors? –  setevoy Jan 17 at 16:34
    
/var/log/cron - in CentOS, in Debian/Ubuntu can be different logfile. –  setevoy Jan 17 at 16:45
    
I bet it's a PATH issue. –  coteyr Jan 17 at 16:49
    
setevoy: Yeah I enabled logging by editing /etc/rsyslog.conf -> uncommenting cron.* /var/log/cron.log -> /etc/init.d/rsyslog restart (DEBIAN) –  Guest in need of help Jan 17 at 16:50

1 Answer 1

By the way - to run cron task every 30 minutes - try to use:

00,30 * * * * [path_to_file]/myscript.sh

share|improve this answer
    
So my format was incorrect? –  Guest in need of help Jan 17 at 16:55
    
*/30 format must work too - but you can try other way if have problems. –  setevoy Jan 17 at 16:56
    
I've tried a million different combinations nothing works... pastebin.com/N3GzHFXU –  Guest in need of help Jan 17 at 19:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.