LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2011, 11:17 AM   #1
shellone
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
Could anyone help me for this "syntax error near unexpected token done" problem


I am a newbie in unix shell script programming . After I have tried to execute this code , I found the problem said that "syntax error near unexpected token done" . I don't know that where is the mistake in my code . Could anyone help me out this problem ?, thank you in advance

PS* : I executed it in Redhat Enterprise Linux 4

and this is my code :

#!/bin/ksh
# Purge Script
# Input:
# 1. path (absolute path)
# 2. filename (does not apply to empty folder name)
# 3. retention policy (in day)
# Example:
# /home/oretail/purge.sh /home/oretail/test/ 'file*' 2
if [ $# -ne 3 ]
then
echo "Error: missing parameter!";
echo '{path} {filepatttern} {retentionday}';
echo "Note: Don't forget to enclose {filepattern} in single quote!"
exit 1;
fi
if [ ! -d "$1" ] #if not directory -> $1
then
echo "Error: $1 is not a directory!";
echo $*
exit 1;
fi
path=$1
expr=$2
days=$3
echo `date`
echo "Running purge with path=${path} expr=${expr} days=${days}"
# finding all files match parameters
# note: The -name test comes before the -type test in order to avoid having to call stat(2) on every file.
cmd="find ${path} -mtime +${days} -type f | egrep -i '${expr}'"
#echo "$cmd"
eval $cmd | while read F
do
echo "$F"
rm -f $F
done
# Knot 7-6-2010 (final)
 
Old 07-23-2011, 11:29 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello shellone, welcome to LQ,

your script is working here. But I didn't check all possibilities for the input. Could you please explain in short, what you expect the script to do? Or which parameters did you use when you got the error?

Markus

Last edited by markush; 07-23-2011 at 11:46 AM.
 
Old 07-23-2011, 12:43 PM   #3
shellone
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for your help , Markush .
The thing I need this program to do , that is , I will pass three parameters consisting of path , expression(part of file name) and days of the file
to purge1.sh to delete the file determining from expression(wanted name) and days(delete file which older than xx days) .
the script line to execute my code is ;

sh /gokCommand/purge1.sh /gok 'zhr*' 1

it is divided into 4 parts
sh [/gokCommand/purge1.sh] (/gok) ( 'zhr*') (1)
sh [path to .sh file which will be executed] (path to folder of file) (expression) (days)

in () -> passed parameters
in [] -> .sh file which I executed

Thank you in advance , Markush .
Shellone
 
Old 07-23-2011, 12:59 PM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello shellone,

I've reported this thread and asked the Moderators to move it to the Programming-forum. I'm not experienced with shell-programming and don't have any knowledge about the Korn-shell.

When I wrote in my first post that the script works on my system, I meant that it runs without errormessages. Now I'll try to understand the code, but hopefully one of the more advanced ksh-users/programmers finds this thread

Markus
 
Old 07-23-2011, 01:09 PM   #5
shellone
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi Markush,

I feel thanked to your kindness help , at least you make me know that my code is work(but why it still shows me the error XD ) . By the way .... if my webboard is moved when person answers my webboard , there will be any notification to me =) ?

shellone
 
Old 07-23-2011, 01:14 PM   #6
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Quote:
Originally Posted by shellone View Post
... By the way .... if my webboard is moved when person answers my webboard , there will be any notification to me =) ?

shellone
This depends on your configuration in your profile. You can configure to receive an "instant email-notification" when anyone answers to a thread you're subscribed to. As far as I remember, the default is that you receive one email per day with the notifications for all answers in any thread you're subscribed to.

Markus

Edit: in your profile "my LQ" look at the left column at "Settings and Options"->"Edit Options" and there you'll find "default thread subscription mode" and can configure the notifications with the dropdown-menu.

Last edited by markush; 07-23-2011 at 01:17 PM.
 
Old 07-23-2011, 11:44 PM   #7
shellone
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Dear Markush,

^^ thank to your suggestion , It is the truth that most of German people always be kind like my sister said . She used to go to German , Berlin . and she was given a postcard from a german grandpa around brandenburgh gate for free . However I think that there will be people who are kind like you in this bbs . Thank you for kindness help in advance
 
  


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
[SOLVED] Script error: "syntax error near unexpected token 'then'" RyuuzakiMasato7 Linux - Server 18 06-20-2011 09:28 AM
syntax error near unexpected token "fi" phillip58 Programming 3 07-05-2009 01:00 PM
syntax error near unexpected token `set' `if ( $dirhome == "." ) set dirhome = `pwd dayanand patil Linux - General 6 01-21-2009 01:52 AM
syntax error unexpected token near "then" pclimmex Linux - Newbie 1 06-20-2008 10:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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