|
Home > Archive > Unix Shell > December 2007 > 0403-057 Syntax error: directory is not expected.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
0403-057 Syntax error: directory is not expected.
|
|
| Rivanor Soares (web_knows) 2007-12-18, 1:32 pm |
| I started writing the code[2] in ksh for the pseudo-code[1] below, but
found a few "issues". At the beginning, I got this:
./cp2notes.sh[17]: 0403-057 Syntax error at line 19 : `$NTSDIR' is
not expected.
Any clues on that? Any help on the code is welcomed as well.
Thanks!
[1] - pseudo-code
'find' the list of .txt files in the /home/casa/dir1 directory that
were modified/created since the last run of this script;
(example find command -> find /home/casa/dir1 -newer /home/casa/dir1/
lastrun -type f -exec ls *.txt {} \\;)
While .txt files remain on the list;
Get a .txt file name;
If there is a like named .txt file in the /home/casa/dir2/
directory Then
Delete the /home/casa/dir2 .txt file;
Copy the /home/casa/dir1 .txt file to the /home/casa/dir2
directory;
Else
Copy the /home/casa/dir1 .txt file to the /home/casa/dir2
directory;
Endif
If there is a like named .ft directory in the /home/casa/dir2/
directory Then
Delete (recursively) the /home/casa/dir2 .ft directory;
Endif
Endwhile
# need to delete .txt/.ft that are in the directory 2 but are not in
the directory 1
'find' .txt files that are in /home/casa/dir2 but are not in /home/
casa/dir1
While .txt file remain on the list;
Get a .txt file name;
Delete the /home/casa/dir2 .txt file;
If there is a like named .ft directory in the /home/casa/dir2/
directory Then
Delete (recursively) the /home/casa/dir2 .ft directory;
Endif
Endwhile
Touch /home/casa/dir1/lastrun file;
[2] - code (written so far)
+8 PIDFILE=/home/casa/lastrun
+9 DATE="`date +"%b%d%Y-%H%M"`"
+10 LOG=/home/casa/txt.log
+11 EPBSDIR=/home/casa/dir1
+12 NTSDIR=/home/casa/dir2
+13 NWFILES="`find $EPBSDIR -newer $PIDFILE -type f -name *.txt`"
+15 #PCKFL=${NWFILES%%\n}
+16
+17 while [[ -n $NWFILES ]]; do
+18 for list in $NWFILES; do
+19 if [[ -n find $NTSDIR -name $list -type f ]];
then
+20 rm $NTSDIR/`cut -f5 -d"/" $files`
+21 cp $files $NTSDIR
+22 else
+23 cp $files $NTSDIR
+24 fi
+25 if [[ -n find $NTSDIR -name $list.ft -type
d ]]; then
+26 rm -R $NTSDIR/`cut -f5 -d"/"
$files`.ft
+27 fi
+28 done
+29 done
+30
+31 #find $NTSDIR -name *.nsf ! $EPBSDIR
+32
+33 touch $PIDFILE
| |
| Rivanor Soares (web_knows) 2007-12-20, 1:26 pm |
| On Dec 18, 6:50 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> Rivanor Soares (web_knows) wrote:
>
>
>
>
>
>
>
>
> Why the while loop? It will never end.
> You certainly want
>
> if [[ -n $NWFILES ]]; then
> ...
> ...
> fi
>
> and you can maybe omit the if .. fi clause,
> because the for will run zero times on an empty list.
>
>
> You maybe want
>
> shortfnam=${files##*/}
> if [[ -f "$NTSDIR/$shortfnam" ]]; then
> rm "$NTSDIR/$shortfnam"
> fi
> cp "$files" "$NTSDIR"
>
> Maybe you can omit the if .. fi
> because cp will overwrite an existing file.
>
> The entire section could be written as:
>
> (
> # get short filenames by cd'ing and run find on '.'
> cd "$EPSBDIR" &&
> find . -newer "$PIDFILE" -type f -name *.txt
> ) |
> while read -r shortfnam
> do
> cp "$EPSBDIR/$shortfnam" "$NTSDIR"
> shortdirnam=${shortfnam%%.txt}.ft
> rm -Rf "$NTSDIR/$shortdirnam"
> done
>
> --
> Michael Tosch @ hp : com
Thanks Mike! It worked fine (mainly the shortfnam=${files##*/} trick,
very cool!).
Here's how my code is looking like so far (and working as expected!):
PIDFILE=/home/casa/lastrun
EPBSDIR=/home/casa/dir1
NTSDIR=/home/casa/dir2
NEWFILES="`find $EPBSDIR -newer $PIDFILE -type f -name *.txt`"
if [[ -n $NEWFILES ]]; then
for files in $NEWFILES; do
shortfnam=${files##*/}
if [[ -f "$NTSDIR/$shortfnam" ]]; then
rm "$NTSDIR/$shortfnam"
cp "$files" "$NTSDIR"
else
cp "$files" "$NTSDIR"
fi
shortdirnam=${shortfnam%%.txt}.ft
if [[ -d "$NTSDIR/$shortdirnam" ]]; then
rm -fR "$NTSDIR/$shortdirnam"
fi
done
fi
touch $PIDFILE
Now, what I'm trying to achieve is: find .txt files (and relative .ft
directories) on the $NTSDIR that doesn't exist on the $EPBSDIR.
Here is the find command I tried:
find $NTSDIR -name "*.txt" \! "$EPBSDIR/*.txt"
But it doesn't seem to work. Any hints on that?
Thanks again,
-- web_knows
| |
|
| On 20 Dez., 15:28, "Rivanor Soares (web_knows)" <riva...@gmail.com>
wrote:
> On Dec 18, 6:50 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Thanks Mike! It worked fine (mainly the shortfnam=${files##*/} trick,
> very cool!).
>
> Here's how my code is looking like so far (and working as expected!):
>
> PIDFILE=/home/casa/lastrun
> EPBSDIR=/home/casa/dir1
> NTSDIR=/home/casa/dir2
> NEWFILES="`find $EPBSDIR -newer $PIDFILE -type f -name *.txt`"
>
> if [[ -n $NEWFILES ]]; then
> for files in $NEWFILES; do
> shortfnam=${files##*/}
> if [[ -f "$NTSDIR/$shortfnam" ]]; then
> rm "$NTSDIR/$shortfnam"
> cp "$files" "$NTSDIR"
> else
> cp "$files" "$NTSDIR"
> fi
> shortdirnam=${shortfnam%%.txt}.ft
> if [[ -d "$NTSDIR/$shortdirnam" ]]; then
> rm -fR "$NTSDIR/$shortdirnam"
> fi
> done
> fi
>
> touch $PIDFILE
>
> Now, what I'm trying to achieve is: find .txt files (and relative .ft
> directories) on the $NTSDIR that doesn't exist on the $EPBSDIR.
>
> Here is the find command I tried:
>
> find $NTSDIR -name "*.txt" \! "$EPBSDIR/*.txt"
>
> But it doesn't seem to work. Any hints on that?
Do you intend to connect two conditions?
Then use the 'and' operator -a (and another -name)...
find dir -name file1 -a -name file2
(additionally negating expressions as necessary)
Janis
> Thanks again,
> -- web_knows
| |
| Rivanor Soares (web_knows) 2007-12-20, 1:26 pm |
| On Dec 20, 1:06 pm, Janis <janis_papanag...@hotmail.com> wrote:[vbcol=seagreen]
> On 20 Dez., 15:28, "Rivanor Soares (web_knows)" <riva...@gmail.com>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Do you intend to connect two conditions?
> Then use the 'and' operator -a (and another -name)...
>
> find dir -name file1 -a -name file2
>
> (additionally negating expressions as necessary)
>
> Janis
>
I tried this:
find dir2 -name "*.txt" \! -a "dir1/*.txt"
find: 0652-017 -a is not a valid option.
Also, saw this on the man page:
3 Expression [ -a ] Expression - Concatenation of
expressions (the AND operation is implied by the juxtaposition of two
primaries
or may be explicitly stated as -a).
Regards.
| |
|
| On 20 Dez., 16:37, "Rivanor Soares (web_knows)" <riva...@gmail.com>
wrote:
> On Dec 20, 1:06 pm, Janis <janis_papanag...@hotmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> I tried this:
>
> find dir2 -name "*.txt" \! -a "dir1/*.txt"
> find: 0652-017 -a is not a valid option.
>
> Also, saw this on the man page:
>
> 3 Expression [ -a ] Expression - Concatenation of
> expressions (the AND operation is implied by the juxtaposition of two
> primaries
> or may be explicitly stated as -a).
>
> Regards.
I had proposed to add (besides the conjunction -a) another -name as
in...
find dir -name *.c -a ! -name xyz*
Janis
| |
| Rivanor Soares (web_knows) 2007-12-20, 1:26 pm |
| On Dec 20, 2:22 pm, Janis <janis_papanag...@hotmail.com> wrote:
> On 20 Dez., 16:37, "Rivanor Soares (web_knows)" <riva...@gmail.com>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> I had proposed to add (besides the conjunction -a) another -name as
> in...
>
> find dir -name *.c -a ! -name xyz*
>
> Janis
Sorry, I got it now. But it's not working as expected. (find dir2 -
name "*.txt" -a \! -name "dir1/*.txt"). It is still listing dir2/ txt
files that does exist in the dir1/.
The idea is to the get the list of files that does exist on dir2/ that
does not exist on dir1/.
Thanks,
-- Rivanor.
| |
| Bill Marcum 2007-12-20, 1:26 pm |
| On 2007-12-20, Rivanor Soares (web_knows) <rivanor@gmail.com> wrote:
>
>
> Sorry, I got it now. But it's not working as expected. (find dir2 -
> name "*.txt" -a \! -name "dir1/*.txt"). It is still listing dir2/ txt
> files that does exist in the dir1/.
> The idea is to the get the list of files that does exist on dir2/ that
> does not exist on dir1/.
>
> Thanks,
> -- Rivanor.
"-name" only matches the last part of the filename. If you want to test
for "dir1/*.txt" you either use "-path" in GNU find, use "-prune" to
avoid searching in dir1, or pipe the output of find to another command
such as grep.
|
|
|
|
|