LinuxQuestions.org
Help answer threads with 0 replies.
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-14-2013, 06:08 PM   #1
misterjones
LQ Newbie
 
Registered: Oct 2011
Posts: 10

Rep: Reputation: Disabled
script fails but works fine when entered line-by-line in terminal


I'm working out a little script to be launched as a cron job that will move some syslog files, compress, and archive them.

Code:
#!/bin/bash

# Script to move logs over 14 days old to a backup folder, then archive them comressed. 

TIME=`date +"%b-%d-%y"`
FILENAME="archive-$TIME.tar"
find /var/opt/syslog/* -mtime +14 -exec mv -v {} /var/opt/backup \;
tar -cvfj /var/opt/archive/$FILENAME /var/opt/backup/*
When I run this in a file, I get an error complaining about

Code:
find: missing argument to `-exec'
However, if I enter each line in bash, everything works fine without error.


Can anyone figure out why I'm getting the error with find?
 
Old 11-14-2013, 06:26 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
#!/bin/bash
set -x
...
and run the script, it'll show the details.

I don't think you need the "*" in find /var/opt/syslog/*

Others may have real answers.
 
Old 11-14-2013, 06:41 PM   #3
misterjones
LQ Newbie
 
Registered: Oct 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
still tripping on that one line.

I can copy and paste the line out of the editor and into a terminal and it works just fine. I really don't get it.
 
Old 11-14-2013, 10:30 PM   #4
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
The manual (man find) mentions that the braces may need to be escaped or quoted to protect them from expansion by the shell. It also has the following example:
Quote:
find . -type f -exec file '{}' \;

Runs `file' on every file in or below the current directory. Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also.
 
  


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
[SOLVED] perl script runs fine from command line but fails when invoked by nagios andrest964 Linux - Newbie 7 10-04-2012 09:04 AM
crontab fails but command line works - sir-lancealot Linux - Server 3 02-19-2011 04:43 PM
Trouble setting up command line wlan that works fine on gnome (ubuntu 9.10) Boffy Linux - Wireless Networking 3 11-13-2009 03:08 PM
Bash script works from command line, fails from cron cmfarley19 Linux - General 4 08-14-2009 12:24 PM
Shell pgm works fine in command line but not in Crontab oracledba_raja Linux - General 2 11-24-2006 12:14 AM

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

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