'unexpected token' error using FIND in script to delete old files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'unexpected token' error using FIND in script to delete old files
# 1  
Old 05-03-2010
'unexpected token' error using FIND in script to delete old files

Hi,

I am compete linux noob, but have managed to setup my Thecus N5500 to rsync to my N5200Pro to do automatic backups each night.

The rsync script also moves any files deleted from the N5500 (and previously backed up to the N5200) to a _deleted folder on the N5200 so I can keep them for 30 days before removing them.

This is where I have run into a problem....

I have the following script that I run on the N5200;
Code:
#!/bin/bash
## This script will delete files older than 30 days from the deleted backups
## generated by nas_backup.sh on NAS1
find /raid0/data/nas_backup/media_deleted/* -mtime +30 -exec rm -f '{}' \;

The problem is I'm getting errors like these when I run the script;
Quote:
root@127.0.0.1:/raid0/data/nsync# sh delete30days.sh
rm: /raid0/data/nas_backup/media_deleted/Library: is a directory
rm: /raid0/data/nas_backup/media_deleted/Library/Master/Cache: is a directory
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `rm -f /raid0/data/nas_backup/media_deleted/Library/Master/Cache/File List Sort/Cache (62).dat'

I don't know if it's any help, but I did have to enclose the {} in quotes '{}' otherwise I got issues with spaces in the directory names as well, which there seems to be great debate in other threads if this is required of not.


I'm not sure what release/version on linux is on the thecus N5200 but I did get this from the box;
Quote:
root@127.0.0.1:/raid0/data/nsync# uname -r
2.6.23N5200
root@127.0.0.1:/raid0/data/nsync# uname -a
Linux nasbackup 2.6.23N5200 #13 Thu May 14 12:47:37 CST 2009 i686 unknown
root@:~# bash -version
GNU bash, version 3.00.16(2)-release (i486-slackware-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
if it's any help.



Can anybody suggest how to fix this please?

Thanks
Richard
# 2  
Old 05-03-2010
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -exec /bin/rm -f {} +

And please refrain from wrongly thinking {} need to be quoted ...
# 3  
Old 05-03-2010
Quote:
Originally Posted by jlliagre
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -exec /bin/rm -f {} +

And please refrain from wrongly thinking {} need to be quoted ...
Thanks for the quick response, the above code gives this error;
Quote:
find: option '-exec' requires an argument

And this code
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -exec /bin/rm -f {} + \;

gives the same error
Quote:
root@127.0.0.1:/raid0/data/nsync# sh delete30days.sh
rm: /raid0/data/nas_backup/media_deleted/Library: is a directory
rm: /raid0/data/nas_backup/media_deleted/Library/Master/Cache: is a directory
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `rm -f /raid0/data/nas_backup/media_deleted/Library/Master/Cache/File List Sort/Cache (62).dat +'
Cheers
Richard

Last edited by rpalmer68; 05-03-2010 at 07:38 PM..
# 4  
Old 05-03-2010
What find version are you using ? It looks like it doesn't know the posix "+" exec delimiter. It looks too it used "sh -c" to run its exec command, which is quite unexpected.
Anyway, try this:
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -type f -exec /bin/rm -f {} \;

# 5  
Old 05-03-2010
Quote:
Originally Posted by jlliagre
What find version are you using ? It looks like it doesn't know the posix "+" exec delimiter. It looks too it used "sh -c" to run its exec command, which is quite unexpected.
Anyway, try this:
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -type f -exec /bin/rm -f {} \;

This gives the same token error I'm afraid.

I'm calling the script with "sh delete30days.sh", I assume this is the correct way to call it?

How do I get the FIND version? find -? gives this;
Quote:
root@127.0.0.1:/raid0/data/nsync# find -?
BusyBox v1.1.0 (2009.03.26-08:00+0000) multi-call binary
Usage: find [PATH...] [EXPRESSION]
Search for files in a directory hierarchy. The default PATH is
the current directory; default EXPRESSION is '-print'
EXPRESSION may consist of:
-follow Dereference symbolic links
-name PATTERN File name (leading directories removed) matches PATTERN
-print Print (default and assumed)
-type X Filetype matches X (where X is one of: f,d,l,b,c,...)
-perm PERMS Permissions match any of (+NNN); all of (-NNN);
or exactly (NNN)
-mtime TIME Modified time is greater than (+N); less than (-N);
or exactly (N) days
-newer FILE Modified time is more recent than FILE's
-inum N File has inode number N
-exec CMD Execute CMD with all instances of {} replaced by the
files matching EXPRESSION
# 6  
Old 05-03-2010
Interesting, so you aren't really using find but a subset of it provided by busybox. BusyBox - Wikipedia, the free encyclopedia

Assuming your system has the "line" command, you might try this:
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -type f -print > /tmp/toRemove
while a=$(line)
do
   rm -f "$a"
done < /tmp/toRemove

# 7  
Old 05-03-2010
Quote:
Originally Posted by jlliagre
Interesting, so you aren't really using find but a subset of it provided by busybox. BusyBox - Wikipedia, the free encyclopedia

Assuming your system has the "line" command, you might try this:
Code:
find /raid0/data/nas_backup/media_deleted -mtime +30 -type f -print > /tmp/toRemove
while a=$(line)
do
   rm -f "$a"
done < /tmp/toRemove

Well the toRemove file looks like it's correct with a list of paths/files, but I'm getting an error;
Quote:
line 5: line: command not found
So I guess that answers that question - no "line" command.

Here's what I have in /bin/, can I install a line command or an updated find somehow?

Quote:
addgroup@ deluser@ ip@ mountpoint@ sleep*
adduser@ df* ipaddr@ mt@ stat@
ash@ dircolors* ipcalc@ mv@ stty@
awk@ dmesg@ iplink@ netstat@ su@
bash* domainname* iproute@ ntpdate* su_root*
bbconfig@ dumpkmap@ iptunnel@ pidof@ sync@
busybox* echo@ kill@ ping@ tar*
cat@ egrep@ ln@ ping6@ touch@
chattr@ false@ loadkeys* pipe_progress@ true@
chgrp@ fdflush@ login@ printenv@ umount*
chmod@ fgrep@ ls@ ps@ uname@
chown@ getopt@ lsattr@ pwd@ uncompress@
cp* grep@ mkdir@ rm@ usleep@
cpio@ gunzip@ mknod@ rmdir@ vi@
date@ gzip@ mktemp@ run-parts@ watch@
dd@ hostname@ more@ sed@ zcat@
delgroup@ insmod@ mount* sh@
root@127.0.0.1:/bin#
Richard
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error near unexpected token `|'

Hi All; I try to write a bash code and I am using command substitution. My code is like: #!/bin/bash IP="10.0.0.1 10.0.0.2" PORT="22 80" USERNAME="admin" SCRIPT_HOST="adminHost" HOME_DIR=/home/admin SCRIPT_DIR=$HOME_DIR/scripts script="sudo /my_remote_script.sh" SSH="/usr/bin/ssh... (7 Replies)
Discussion started by: Meacham12
7 Replies

2. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

3. Shell Programming and Scripting

Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good. I appreciate... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `('

What do I do here? #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill... (2 Replies)
Discussion started by: iiiiiiiiiii
2 Replies

5. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

6. UNIX for Dummies Questions & Answers

Syntax error near unexpected token

hi! just want to seek help on this error: syntax error near unexpected token 'do this is my script # !/bin/sh # for y in 27 25 do exemmlmx -c "ZEEI;" -n XRT$y >> blah done what can be wrong? thanks! (6 Replies)
Discussion started by: engr.jay
6 Replies

7. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

8. UNIX for Advanced & Expert Users

syntax error near unexpected token '{

Hi, I am running the following script through cygwin and getting below mentioned error. ******************************************* #!/bin/sh # constants WORK_DIR="deploy" INFOFILE="deploy.info" INTROFILE="Intro.sh" CMGMT_PKG="com.kintana.cmgmt.deploy" DEPLOY_PREFIX="mitg" ... (2 Replies)
Discussion started by: MandyR
2 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

10. Shell Programming and Scripting

While loop error: Unexpected token done

I have tried to implement a while loop into the code but upon running the following code i am getting the errors: ./Assigntest: line 42: syntax error near unexpected token `done' ./Assigntest: line 42: `done' The code is as follows: #!/bin/bash #Filename: Assignment Author: Luke... (9 Replies)
Discussion started by: warlock129
9 Replies
Login or Register to Ask a Question