My Cronjob is not running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My Cronjob is not running
# 1  
Old 02-20-2012
My Cronjob is not running

I created a script,

Code:
size=`du -sm`
size=`echo $size | sed 's/.$//'`
size1='30720'
if [ $size -gt $size1 ]
then
{
find /ask/tarballs -type f -name "*.tgz" -mtime +30 -exec ls -l {} \;
find /ask/tarballs -type f -name "*.tgz" -mtime +30 -exec rm -f {} \;
}
else
echo "Directory size doesnt exceed Threshold Limit"
fi

==============
which is in the directory path /ask/tarballs

so i created a cronjob like

Code:
crontab -e

inside that i gave the command

Code:
01 * * * * /ask/tarballs/tar1.sh

then pressed Esc button and saved as :wq
so that it should run every minute..

But the script is not running as per the scheduled task..

Could you help me with this..?

Last edited by methyl; 02-20-2012 at 07:38 AM.. Reason: please use code tags
# 2  
Old 02-20-2012
It won't run every minute.

With this setup it will run every hour and 1 minute.g 16.01 , 17.01 etc.
Setup for every minute is all `*'
Code:
* * * * * /ask/tarballs/tar1.sh

Also please use code tags when posting code.
# 3  
Old 02-20-2012
what is your cron log says ?

check under /var/log
# 4  
Old 02-20-2012
Jobs run by cron run in background with no terminal context. Any output from your cron will not go to a terminal. It will go to unix mail for the user who owns the cron (unless you redirect the output to a log file).

Please post what Operating System and version you have and what Shell the script was written to use. The default Shell for cron is usually /bin/sh which on some O/S like Solaris is a very old Bourne Shell.

Please mention which user owns this crontab and post the output from:
Code:
ls -lad /ask/tarballs/tar1.sh

# 5  
Old 02-20-2012
Its showing
You have new mail in /var/spool/mail/root

But how to check that mail..??

And also the script hasn't ran at all.. coz it doesnt delete the file which is 30 days older

---------- Post updated at 05:28 PM ---------- Previous update was at 05:21 PM ----------

@ methyl : i dont understand wat u r saying.. as am a newbie to Unix.. Could u kindly convey message simply as i could understand.. Sorry, I think u could understand.. Thanks for Understanding

---------- Post updated at 05:33 PM ---------- Previous update was at 05:28 PM ----------

Inside the path

Code:
/var/spool/mail/root

The cronjob results showed as below

Code:
/bin/sh: /ask/tarballs/tar1.sh: Permission denied

Why is this so..?? could u please help me with that

Last edited by methyl; 02-20-2012 at 08:20 AM.. Reason: code tags
# 6  
Old 02-20-2012
If you were logged in as "root" then the cron is owned by root.

Code:
#To find out your Operating System and version:
uname -a
#To find out your normal Shell
echo $SHELL

The mail file is a text file. You can read it with "more" or "tail". In your case at 12:01 GMT you should find it quite easily:
Code:
tail -200 /var/spool/mail/root | more

There are proper ways of reading the mail but we are probably just looking for an error message or other output from your cron.

The permissions of the script file are important. It must be executable by the owner of the cron.
Code:
ls -ald /ask/tarballs/tar1.sh


(POSTS CROSSED)
You need to make the script file executable.
Code:
chmod 755  /ask/tarballs/tar1.sh

Also note that the error message in your post came from /bin/sh which is the default Shell from cron.
If the default Shell from your user is different you will need a shebang line at the top of your script.
# 7  
Old 02-20-2012
The permission is

Code:
-rw-r--r-- 1 root root 294 Feb 19 23:26 /ask/tarballs/tar1.sh

The cronjob results showed as below

Code:
/bin/sh: /ask/tarballs/tar1.sh: Permission denied


Last edited by methyl; 02-20-2012 at 08:21 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cronjob not running on Ubuntu 14.04

I have created a test cronjob using crontab -e that runs a script at /home/cmccabe/cron.sh. I am not sure the script doesn't run though I can call it in terminal. Thank you :). crontab -e (run script sat at 6:10pm)? 10 18 * * 6 /home/cmccabe/cron.sh contents of cron.sh #!/bin/bash... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Facing issues while running a cronjob !

Hi, I am trying to run a cronjob. But while doing so I am getting the following error message :- can't open yourfile in /var/spool/cron/crontabs directory. No such file or directory How can I resolve this issue ? Please help. Thanks Please view this code tag video for... (14 Replies)
Discussion started by: acidburn_007
14 Replies

3. Shell Programming and Scripting

cronjob not running but runs manually

hello, i recently switched to a new ec2 box and transferred the cronjobs from the old box. For some reason one of the scripts won't work but it runs manually from the command line. I've read from previous threads it might be an environment issue but I added a line with the path to the script... (2 Replies)
Discussion started by: lencholamas
2 Replies

4. UNIX for Dummies Questions & Answers

Script not running through Cronjob

Hi, I have a .ksh script which updates the database. The script is running fine manually but it is not running through cron.All the file permissions are fine. The script contents are as below: #!/usr/bin/ksh ddate=`date +%Y%m%d` echo $ddate nohup sqlplus crm/crm @db_state_sync.sql >>... (3 Replies)
Discussion started by: shivangi
3 Replies

5. Shell Programming and Scripting

Cronjob not running

Hi, having problem running my cronjob, need the script to run every monday. And the error i'm getting is "No such file or directory", i've tried to change the env to /bin/bash and also /usr/bin/sh but both failed. Need help here. tq 0 0 * * 1 /bin/bash /home/omc/munir/raccli_rnc.sh Rgds... (3 Replies)
Discussion started by: adawiyah29
3 Replies

6. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

7. UNIX for Advanced & Expert Users

SYS CRONJOB just not running...

I'm trying to run "SAR -i 60" under #/var/spool/cron/crontabs/SYS 0,10,20,30,40,50 0-6 sh -c "/usr/lib/sa/sa1 60 10 &" 55 23 * 0-6 /usr/lib/sa/sa2 -i 900 -A machine is not running above cron job under "sys" at all. This suppose to run every minutes and all time in 24 hours. When day... (6 Replies)
Discussion started by: deal732
6 Replies

8. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/prd_pre_to_post.sh 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

9. UNIX for Advanced & Expert Users

Cronjob is not running

hi, I have a shell script which has a sql plus code and unix if else condition. The file is located at root.I logged in as a root user and i have all permissions. I tried to set up a cron job so that the script need to run every minute.the script is running successfully without any problem. I... (2 Replies)
Discussion started by: sanei05
2 Replies

10. Shell Programming and Scripting

Shell script not running thru Cronjob

Hi I have a shell script, it run ok if executed from the path it is located at but doesnot run when the same is tried through cron-job. can someone help me please. regards gaurav shrinivas Email address removed (8 Replies)
Discussion started by: gauravshrinivas
8 Replies
Login or Register to Ask a Question