LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 03:18 PM   #1
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 116

Rep: Reputation: 7
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, 03:55 PM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

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

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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, 04:29 PM   #4
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 116

Original Poster
Rep: Reputation: 7
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, 10:04 AM   #5
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 116

Original Poster
Rep: Reputation: 7
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:34 PM.

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
Open Source Consulting | Domain Registration