Cronjob not running

 Newbie to Unix (Solaris).

I wanted to remove all the files existing in a directory every 5 mnutes.
The files that i need to remove are log files and every minute it generates 3/4 files.

I set up a cronjob for this activity but the files are not getting deleted for some reason.

Cron job used :
*/5 * * * * rm -rf /opt/app/addop/newsystem/ars/bmc/apps/service/debug/*.dbg
Also used following cronjob (for solaris) but in vain
0,5,10,15,20,25,30,35,40,45,50,55 * * * * rm -rf /opt/app/addop/newsystem/ars/bmc/apps/service/debug/*.dbg

The rm command when it is executed diretly works fine.
rm -rf /opt/app/addop/newsystem/ars/bmc/apps/service/debug/*.dbg

Please help
Who is Participating?
Michael WorshamConnect With a Mentor Infrastructure / Solutions ArchitectCommented:
Sometimes variables in command line actions aren't copied correctly in cron. It might be better to create a script (i.e. then use cron to call the executable script instead.

*/5 * * * * /path/to/

# Remove files from a certain directory (
rm_cmd='/bin/rm -rf'
$rm_cmd $DIRECTORY/*.dbg

Open in new window

Michael WorshamInfrastructure / Solutions ArchitectCommented:
For cron, you have to state where the command actually resides -- i.e. '/bin/rm'
Kerem ERSOYPresidentCommented:

which rm

then get the path add before the rm command.

Also I don't think the syntax :
*/5 is valid for solaris try the second version instead..

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

first form is not supported in solaris:

*/5 * * * * rm -rf /opt/app/addop/newsystem/ars/bmc/apps/service/debug/*.dbg

in 2nd form , use full path name to rm

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/rm -rf /opt/app/addop/newsystem/ars/bmc/apps/service/debug/*.dbg
Brian UtterbackPrinciple Software EngineerCommented:
I think you already said that you did not use the */5 on Solaris, did you not? So that isn't the problem.

Nor is the problem having to give the full path to rm.  The PATH set up in cron is minimal, but not non-existent, and
rm is on the default path cron uses, so that isn't the problem.

Are you running the job as a regular user or as root? If you are running as a regular user, perhaps there is a
permissions problem. When you said it worked outside of cron, are you sure you were running as the same
user? If you are running the job as root, then is the directory NFS mounted? That might prevent the rm from

Have you checked the local mail for the user you are running the job for? If cron encounters an error, it wil
send the output of the command to the local mail file. Try running just "mail" as they user.

One other thing. If you are running the cron job as root, consider not doing so. I presume that there are files
being created in the directory by others, otherwise why delete them? If it is at all possible for a random
user to create a file in that directory that houses the debug files, (i.e. world writable) then you need to rethink
your script.  Consider what would happen if I were able to create a file with the following name:

" $SHELL f.dbg"

in the directory. The glob you have would execute the command
rm -rf //opt/app/addop/newsystem/ars/bmc/apps/service/debug/  /usr/bin/sh f.dbg

That woould be bad, I think. And there are even worse possibilities.
Brian UtterbackPrinciple Software EngineerCommented:
I don't get it. What was the solution? There weren't any variables in the original script to be copied, so how
would putting it into a script help? If the PATH isn't set to the default, that would be a bug in cron. So what happened?
I agree with blu.  Assuming the initial crontab entry was correctly defined and running as the correct user and cron was running, then it should have needed no changes.

Something else was the problem and certainly didn't need a separate script to be written (although in general, this is not a bad approach)
If your platform is Sun solaris, then the accepted solution will not run since */5 * * * *  format is not supported.

I think author is requested to explain why that solution was accepted.
Kerem ERSOYPresidentCommented:
The representation "0/5" would not run in solaris Crontab as I told earlier in the tread. Also I really can't understand what does this script in accepted solution do that the command in the inital post does not. I am not sure if there's a bad intention in that but it is obvious that the question and the answer would not help anyone later searching the tread. What about opne a question in expert area for the evaluation of sys admins?
Michael WorshamInfrastructure / Solutions ArchitectCommented:
Actually in this case I agree with the other EE experts that I didn't give a 'full' solution in this case. I just supplied a partial solution via using a script rather than placing the actual rm/delete statement within the crontab entry. When referring back to the question, the 'asker' stated they were a 'newbie' when using Solaris... so it is my guess that the asker wanted something with detail (i.e. an example script) thus something a bit more concrete to work from rather than a full, drawn out explanation on why his/her original question wasn't working.
Kerem ERSOYPresidentCommented:
Yeah but what could have he possibly learnt from your script while the content is not new or concrete? Furthermore it is even not possible to get it worked with "0/5" thing :)

We're all here for some time now. We've all seen an asker gave credit to someone contributed lesser then the others. But in this case there's nothing to contribute. Even it does not work as you suggested. This is what we're having difficulty to understand.
Michael WorshamInfrastructure / Solutions ArchitectCommented:
@KeremE: Do an attention request for the question. Maybe a zone advisor can get in touch with the asker or reassign the points, etc. Doesn't hurt my feelings any. ;)
tks_g100Author Commented:

Hi all,

 I regret for my late posting here. I was tied up with my release activities which is due today and hence could not get time to reply to my post.

As i mentioned earlier in my question i tried both the commands and both were not working and i was in hurry to make this cron running to delete the growing log files in that path.

 The accepted solution (through script) worked perfectly fine for me (i used /5 only).
I am not sure really how it worked even by giving /5 to the solaris machine.

Before trying the script i also tried adding the location rm command even then it din't worked.
I lost my control of experimenting things with the command and i finally tried that accepted solution (through script) and worked fine for me.

 I really don't know how this script worked but not my command. Searching for the same answer. If anyone requires any additional information which can unfold the mystery i am here to give.

Once again thanks for the valuable information and discussion with this post and i regret the inconvenience caused for my delayed response.

Note: My response may get delayed as i am working from India.
thank you, can you do

uname -a
crontab -l

and post output
tks_g100Author Commented:
uname -a
SunOS servername 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-15000
crontab -l
1 0 * * * /usr/sbin/logadm
2 0 * * * /usr/sbin/svcadm restart system-log
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
*/5 * * * * /home/

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.