LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 11-14-2011, 06:58 AM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 43
cron job to create snapshots not working


When I run the following from the command line -

Code:
zfs snapshot zones/lake/LOCAL/logictrap@$(date "+%Y%m%d")
i get a lovely snapshot of my filesystem. When I run the same command from cron -

Code:
3 3 1,7,14,28 * * 'zfs snapshot zones/lake/LOCAL/logictrap@$(date "+%Y%m%d")'
i get an error -

Code:
sh: line 1: zfs snapshot zones/lake/LOCAL/logictrap@$(date "+: not found
Why is this? I have tried different ways of quoting the command but always the same error. Also i've not had these kinds of syntax errors before with cron (though I have used Linux cron previously).

Thanks in advance

spoov
 
Old 11-14-2011, 07:03 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Have you tried it without the quotes:
Code:
3 3 1,7,14,28 * * zfs snapshot zones/lake/LOCAL/logictrap@$(date "+%Y%m%d")
 
Old 11-14-2011, 07:04 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You need to escape the % signs, because they have a special meaning in crontab:
Quote:
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the first % will
be sent to the command as standard input.
Your job should be:
Code:
1,7,14,28 * * zfs snapshot zones/lake/LOCAL/logictrap@$(date +\%Y\%m\%d)
 
1 members found this post helpful.
Old 11-14-2011, 07:21 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by colucix View Post
You need to escape the % signs, because they have a special meaning in crontab
Thanks colucix I missed that
 
Old 11-15-2011, 04:24 AM   #5
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Thanks I thought it would be something needed escaping but didn't know what!

Thanks again
 
  


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
How to create cron job to execute at same time each day? damgar Slackware 4 11-19-2010 06:27 PM
cron job to create and move backup from ubuntu to windows. onlykishore07 Linux - Newbie 1 06-15-2010 01:49 PM
How to create a cron job and run it ,give simpleexample ramakrishnankt Linux - Newbie 18 12-04-2009 07:52 AM
How to create user account with a 'newusers' run from a cron job? tifoso Linux - General 3 11-05-2009 06:19 AM
How to create a cron job to delete a folder's contents? s0n|k Linux - Newbie 1 10-05-2007 07:59 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

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