LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-30-2013, 10:03 AM   #1
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Rep: Reputation: 0
Problems excuting a script through cron


This is driving me a bit crazy(er). I haven't had to work with Linux in a while and I know I am missing something but cannot put my finger on it. I have google it to death and have just given up.

I know it is somewhere in the permissions but can not for the life of me figure it out so I have come for help.

I need to delete a file while th DB is down. The DB is down but when I come in the file is still there.
I have even tried a test file (one that I have vi'ed and I own) and still can not get it work through cron. I can delete it by executing it(./)

I will not bore you with my test file. Here is a listing of the prod file:
-rw-r--r-- 1 root root 17383315 2013-01-30 09:51 dklog.log

When I created the script I created it as root here is the listing of it:
-rwxrwxrwx 1 root root 46 2013-01-28 07:21 dklogremv.sh

And here is the script:
date
cd /opt/WebSphere/AppServer
rm dklog.log

Here is the crontab listing:
59 1 * 1-12 0 /opt/scripts/dklogremv.sh > /opt/scripts/dkremov.log

The file does exist in this directory (/opt/WebSphere/AppServer)
What am I missing????
Any help is deeply appreciated.
 
Old 01-30-2013, 10:08 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,448

Rep: Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210
and what is in /opt/scripts/dkremov.log?
 
Old 01-30-2013, 10:21 AM   #3
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
I am sorry it si the script i posted:
And here is the script:
date
cd /opt/WebSphere/AppServer
rm dklog.log
 
Old 01-30-2013, 10:27 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
What pan64 was asking is to show the content of the log file /opt/scripts/dkremov.log, since you used redirection in the crontab entry. Also check the mail of the crontab owner, where standard error (not redirected to a file) should have been sent (if any).

An aside note: what is the purpose of the 1-12 interval in the month field? Doesn't it equal to * (month not restricted)?
 
1 members found this post helpful.
Old 01-30-2013, 10:45 AM   #5
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
There is nothing in it, that is another mystery. the first time it executed there was nothing so I put the date command in it to see if it was executing.
Yes 1-12 is the same as *, truthfully I don't know why I did it
 
Old 01-30-2013, 11:02 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Ok. A silly question: have you tried a simple crontab entry to see if it is a generic problem like "the system doesn't let my user run cron jobs" or "the cron daemon is down"? Example:
Code:
*/5 * * * * date >> $HOME/cron.log
This should run every 5 minutes, that is at 0,5,10,15.... minutes of every hour.
 
Old 01-30-2013, 11:06 AM   #7
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
Part of the problem is this is roots' crontab and I have at least 10 other simular functions.
So I set up a cron for my own user id with a test file and I can not get that one to delte either using cron
 
Old 01-30-2013, 11:11 AM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
But does this execute from your own user's crontab?
Code:
*/5 * * * * date >> $HOME/cron.log
I mean apart the permissions problems of the script in /opt (if any).
 
Old 01-30-2013, 01:07 PM   #9
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
Yep works:

cron.log Documents public_html test1
cat cron.log
Wed Jan 30 13:55:01 EST 2013
Wed Jan 30 14:00:01 EST 2013
Wed Jan 30 14:05:01 EST 2013

Last edited by ljmace1953; 01-30-2013 at 02:02 PM.
 
Old 01-30-2013, 02:26 PM   #10
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Ok, the user's crontab is working. Now about the permissions: the script should be executable by the user (but you can always change the ownership of the script). The file instead cannot by removed by a normal user, not only because permissions prevent it:
Code:
-rw-r--r-- 1 root root 17383315 2013-01-30 09:51 dklog.log
but also because the directory where the script is placed should belong to (or have permissions for) the crontab owner. And maybe for this reason the log file placed in the same directory has not been updated by the date command in your script. What about trying something like this, just for testing purposes?
Code:
*/5 * * * * /opt/scripts/dklogremv.sh > $HOME/cron.log 2> $HOME/cron.err
 
Old 01-31-2013, 07:29 AM   #11
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
I had to use the script for my test file and the cron statement worked. I don't know why though.
The file i need to remove is a DB2 log that is in use and I will not have a chance to remove until Monday morning.
BUT I am more than a little confused why this worked all the sudden!
I will not update this until Monday when i get in. I will add the correct cron job back into roots' crontab.
Thank you very much!
 
Old 02-04-2013, 09:28 AM   #12
ljmace1953
LQ Newbie
 
Registered: Jan 2006
Distribution: suse
Posts: 23

Original Poster
Rep: Reputation: 0
I want to thank all of you for your help.
I am a bit embarssed to say that after thes testing examples given by colucix i really began to look at the script.
Well long story short I was pointed at the wrong library.
Again, thank you for all your help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not access LAN unless excuting network restart script samohn Linux - Newbie 4 08-27-2008 11:44 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
script problems for cron ABL Linux - Software 3 12-16-2007 04:43 AM
Problem excuting cgi script in OpenBSD gani *BSD 3 05-26-2005 06:40 AM
script/cron problems plisken Programming 3 08-12-2003 01:10 AM


All times are GMT -5. The time now is 12:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration