LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-03-2005, 04:24 PM   #1
UrbanSlayer
LQ Newbie
 
Registered: Apr 2004
Posts: 14

Rep: Reputation: 0
Command works on cmdline, not in cron?


Im a bit stuck with this, ive fiddled with the command, googled, and asked a few friends that also know Linux, but they werent sure why this command works fine on the commandline, but not when I install it into crontab.

I'm hoping someone can shed some light on this!

The command -

Code:
tar -zcf /mnt/80GB/Mailbackup/`date +%F`.tar.gz /home/chise/Maildir/
This is what I have installed in cron -

Code:
0 0 * * 0 tar -zcf /mnt/80GB/Mailbackup/`date +%F`.tar.gz /home/chise/Maildir/
I also tried it with
Code:
"`date +%F`"
But always I get the same error, which is -

Code:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
Thats only when I use it from cron, otherwise the command works fine.

Can anyone help?

Thanks in advance!

Last edited by UrbanSlayer; 11-03-2005 at 04:25 PM.
 
Old 11-03-2005, 05:05 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
There are two issues that usually catch folks when trying to do things in cron that work OK manually.

The first is that paths may not be the same. Use fully qualified command names. For example, instead of:

tar ...
date ...

use:

/bin/tar ...
/bin/date ...

The second issue is that the shell is usually not the same. Most folks use bash at the command line, but frequently cron is set to use sh. You can put your commands into a file prefixed with:

#!/bin/bash

to insure that it runs under the shell you want it to.

Alternatively, you can make changes to /etc/crontab, but that may not be viable if you don't have root access on a machine.
 
Old 11-04-2005, 02:05 AM   #3
UrbanSlayer
LQ Newbie
 
Registered: Apr 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks!

I'll give that a go, and see how it works.

As an aside - I did try it in a file, but it didnt actually do anything, in the end.
 
Old 11-06-2005, 05:27 AM   #4
UrbanSlayer
LQ Newbie
 
Registered: Apr 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Unfortunately, that didnt work.

I edited /etc/crontab to use bash instead of sh, and also put in the direct path to the 2 commands I was using, but I still got the same error that is in my above post.

Do I need to restart cron for it to take the changes I made to crontab?

Or, is there a way to make the command run under sh instead of bash?

Thanks!
 
Old 11-06-2005, 09:43 AM   #5
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Cron will detect and load modifications to all crontabs. From the man page:

Additionally, cron checks each minute to see if its spool directory’s modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified.
 
Old 11-06-2005, 10:49 AM   #6
UrbanSlayer
LQ Newbie
 
Registered: Apr 2004
Posts: 14

Original Poster
Rep: Reputation: 0
And that includes the actual crontab configuration file?
 
Old 11-06-2005, 11:14 AM   #7
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
That's how I read it. If you have doubts, restart cron. On a Redhat-based distribution:

/sbin/service crond restart
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
btdownload*.py, works from Command Line, not from cron SkipHuffman Linux - Software 11 12-30-2005 02:55 PM
works on command not on cron rickict Linux - General 1 11-17-2005 02:52 PM
cron command alphamike Linux - Newbie 2 08-28-2005 12:04 AM
Help with a cron command phatboyz Linux - Software 2 01-19-2005 11:09 AM
How to use cron command in solaris meng_en General 1 11-06-2002 09:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:11 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