Re: error on script to copy files (384 Views)
Reply
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 1 of 15 (442 Views)
Accepted Solution

error on script to copy files

Hi

I have the following script to copy files from one directory to another:

 

#!/bin/sh
touch -mt 201304240000 /var/tmp/ref1
touch -mt 201305152359 /var/tmp/ref2
find /moneta_collected02/in_psl -type f \( -newer /var/tmp/ref1 -a ! -newer /var/tmp/ref2 \) > file_lst
cp -pr $(< file_lst) /moneta_collected02/in_psl1/

 but when I run I have the following error:

 

root@moneta # ./transf
find: stat() error /moneta_collected02/in_psl/PSLCCN4-130106-0731-90574.gz: No such file or directory
./transf: syntax error at line 5: `(' unexpected

 please can you help?

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 2 of 15 (430 Views)

Re: error on script to copy files

>find: stat() error /moneta_collected02/in_psl/PSLCCN4-130106-0731-90574.gz: No such file or directory

 

It's almost as if the file as removed just as it found it.  ??

You can suppress this by adding "2> /dev/null" to the end of the find.

 

>./transf: syntax error at line 5: `(' unexpected

 

You may have to check to see if file_lst is not empty before doing the cp:

if [ -s file_lst ]; then

   cp -pr $(< file_lst) /moneta_collected02/in_psl1/

fi

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 3 of 15 (427 Views)

Re: error on script to copy files

 

Hi!

 

With the change suggested by Dennis, I am having the same error:

 

root@moneta # ./transf
find: stat() error /moneta_collected02/in_psl/PSLCCN4-130106-0731-90574.gz: No such file or directory
./transf: syntax error at line 7: `(' unexpected

 line 7 is :

 

 cp -pr $(< file_lst) /moneta_collected02/in_psl1/

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 4 of 15 (426 Views)

Re: error on script to copy files

Have you looked inside of file_lst to see if valid filenames?

 

Otherwise that syntax is perfectly valid for a real shell.

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 5 of 15 (424 Views)

Re: error on script to copy files

this is what is inside:

 

root@moneta # head file_lst
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130506-0009-198970.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130506-0009-198969.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130506-2332-203175.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130506-2332-203176.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2331-185808.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2330-185806.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2331-185807.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2357-185888.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2357-185887.gz
/moneta_collected02/in_psl/130304-1530-PSLCCN2-130502-2357-185886.gz
root@moneta #

 which is correct, unless the script does not want the directory  (moneta_collected02) and the subdirectory (in_psl1)

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 6 of 15 (416 Views)

Re: error on script to copy files

>this is what is inside: ... unless the script does not want the directory

 

No, that full path is fine.

What OS version are you using?

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 7 of 15 (407 Views)

Re: error on script to copy files

Hi

 

It does work now after inserting the condional format (if) on HP-UX 11.31, but I try to use a similar script on a solaris 10 system and it gives me that error message.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 8 of 15 (404 Views)

Re: error on script to copy files

>I try to use a similar script on a solaris 10 system and it gives me that error message.

 

Because Solaris isn't using a real shell for /bin/sh.  You need to use a Posix or ksh.

Or you can go back to the bourne dark ages:

   cp -pr `cat file_lst` ...

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 9 of 15 (402 Views)

Re: error on script to copy files

you mean changing the #!/bin/sh by #!/bin/ksh ?
Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 10 of 15 (396 Views)

Re: error on script to copy files

After changing to ksh now I have a different error:

 

./transf[7]: /usr/bin/cp: arg list too long

 But I believe if the shorten the markers :

 

touch -mt 201304240000 /var/tmp/ref1
touch -mt 201305152359 /var/tmp/ref2

 I can solve this

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 11 of 15 (396 Views)

Re: error on script to copy files

>you mean changing the #!/bin/sh by #!/bin/ksh?

 

Yes, that will do it.

(Of course there may be issues similar to HP-UX where shell scripts may have to use /sbin/sh so they work if /usr isn't mounted.)

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 12 of 15 (394 Views)

Re: error on script to copy files

After changing to ksh now I have a different error:

./transf[7]: /usr/bin/cp: arg list too long
But I believe if the shorten the markers :

touch -mt 201304240000 /var/tmp/ref1
touch -mt 201305152359 /var/tmp/ref2
I can solve this
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 13 of 15 (393 Views)

Re: error on script to copy files

>./transf[7]: /usr/bin/cp: arg list too long
>But I believe if the shorten the markers :

 

But why would you want to settle?  :-)

 

The correct solution on HP-UX and Linux would be to use: find ... -exec special-cp-script {} +

But assuming your files are large and it isn't worth trying to use xargs or write that above script, can use:

for file in $(< file_lst); do

   cp -pr $file /moneta_collected02/in_psl1/

done

Please use plain text.
Super Advisor
NDO
Posts: 533
Registered: ‎12-10-2003
Message 14 of 15 (386 Views)

Re: error on script to copy files

thanks a lot, I have tried that but I am certain is going to work, thanks again for your help
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 15 of 15 (384 Views)

Re: error on script to copy files

>I have tried that but I am certain is going to work, thanks again for your help

 

Sure.

If you have performance issues, we can use the find/xargs solutions to invoke cp with multiple files.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation