Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.