LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-28-2013, 04:18 PM   #1
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Rep: Reputation: 5
Not sure why this command isn't working under bash and cron


Hi,

I have a bash script on a Fedora 16 box which I use to back-up the machine.

The script does what it is supposed to in terms of backing everything up to an external drive, but part of the script doesn't work under cron.

However, if, from the command line, I run the bit which fails in the script, then it works with no problem. The command is designed to delete files older than 10 days.

The script is kicked off under root cron like this:

nice -n 19 /home/cheddar/bits/backup.sh

The command inside the script, to delete the files is this:

find "/media/Media Drive/Backups/" -type f -ctime +10 -exec rm -f {} \;

It's that command which doesn't work when the script is run with cron, even though the syntax is correct and works from the command line.

The script has a group owner of root, and group has rwx permissions.

No errors reported in /var/log/cron...

Any assistance much appreciated!

Cheddar.
 
Old 04-28-2013, 04:55 PM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,415

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
Try with the full PATHs to the commands in the script.
cron executes with a limited environment.
 
Old 04-28-2013, 05:14 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Shouldn't find "/media/Media Drive/Backups/" -type f -ctime +10 -exec rm -f {} \; be find "/media/Media Drive/Backups/" -type f -ctime +10 -execdir rm -f '{}' ';' ? If you don't escape the curly brackets, bash should parse them to an empty list.
 
Old 04-28-2013, 05:29 PM   #4
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by PTrenholme View Post
Shouldn't find "/media/Media Drive/Backups/" -type f -ctime +10 -exec rm -f {} \; be find "/media/Media Drive/Backups/" -type f -ctime +10 -execdir rm -f '{}' ';' ? If you don't escape the curly brackets, bash should parse them to an empty list.
Hmmm, interesting ... that sounds quite logical. I'll amend the script for tomorrow night and see what happens.

Thank you!
 
Old 05-12-2013, 11:04 AM   #5
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Thanks for the suggestion. Although it didn't appear to work with "-execdir" it did work with "-exec" which I'd been trying to use; but, along with your other modifications it now works.

However, I now happen to have a separate, but related problem, which I'll create a new post for.
 
  


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
Pipe inside variable isn't working in bash Reginald0 Linux - General 6 12-09-2015 10:56 AM
./configure command isn't working in command line jumpmansbro Linux - Newbie 20 01-22-2009 09:29 PM
"service __ restart" bash command isn't working case1984 Linux - Newbie 9 04-10-2008 03:35 PM
Cron Scheduling isn't working for me, can someone walk me through this? gohmifune Linux - Software 5 08-16-2007 09:12 PM
exporting variables under bash isn't working! dtheorem Programming 6 03-11-2004 09:35 AM


All times are GMT -5. The time now is 04:01 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration