Ksh errors while copying a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ksh errors while copying a directory
# 1  
Old 05-12-2009
Ksh errors while copying a directory

Hello all,

I have a ksh script run on Solaris 10 by the root user. The section that's giving me errors is the following:

VAR=$(perl -lne '...')

if [[ "$VAR" == "" ]] ; then
print "$VAR undefined"
fi

recover_files {
print "Recovering the files..."
cd ${VAR}/files
cp -pr nfs /destination
print "Files recovered"
}

$VAR is correctly defined (I don't see the error message displayed), however, when reaching the recover_files function, I have the following errors:

....
Recovering the files...
./my_script.sh[3]: */files: not found
cp: cannot access nfs
...

On a second run of the script, no error is displayed anymore, and the nfs directory is copied to the destination.
The "cannot access" error tells me that I was trying the cp from a wrong location, but I can't really figure out the first error - can someone help?

Thank you,
Adrian
# 2  
Old 05-12-2009
As posted the script contains syntax errors which may be masked by other oddities in the script such as misplaced quotes or brackets. We really need to know what the perl program puts into $VAR. As posted it is a syntax error because the program name is missing. Somehow $VAR="*" at the time of the "cd".

I believe that this construct is invalid.
Quote:
recover_files {
print "Recovering the files..."
cd ${VAR}/files
cp -pr nfs /destination
print "Files recovered"
}

There are two syntaxes for functions in ksh.

Code:
subroutine1 ()
{
ls -la
}
# Execute subroutine1
subroutine1
#
function subroutine2 {
ls -la
}
# Execute subroutine2
subroutine2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with copying from one drive to another with cgi & ksh script

Hi I was hoping some one could help me with a problem I have with a .cgi script I am running in the korn shell. I have created a web form that user fill out to gather information that I use a .cgi and sed script to translate into a xml file which is further processed by another program. All is... (6 Replies)
Discussion started by: Paul Walker
6 Replies

2. Shell Programming and Scripting

need help with ksh script errors

#!/bin/ksh number1="20" if then number1=$1 fi number2="1" while ] do if ] then print "FizzBuzz" elif ] then print "Fizz" elif ] then ... (3 Replies)
Discussion started by: bjhum33
3 Replies

3. Shell Programming and Scripting

Copying subdirectories of a directory to some other directory and renaming them

Hi, I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory. please... (8 Replies)
Discussion started by: sholay
8 Replies

4. Shell Programming and Scripting

Copying files to a directory

Hi I have a few questions. I am trying to copy a file to a directory. I need to copy files that do not end in numbers, for example, into a directory. This is what I tried so far. cp filename directorytowhereIwannacopy but it says it can't copy to a directory. I need to copy many files into one... (2 Replies)
Discussion started by: #moveon
2 Replies

5. Shell Programming and Scripting

Copying files from one directory into another.

Could someone please tell me if there is a command similar to head or tail that can be used on directories. I want to select a given number of files from a directory and copy them into another directory. But I found out I can't use head as it doesn't (or I don't know how yet!) work on directories.... (4 Replies)
Discussion started by: Krush187
4 Replies

6. Shell Programming and Scripting

Copying curent directory

I am trying to write a script that first copies all the directories and files from the current directory into a new Directory. I get and error "Cannot copy directory into itself". That's fine. I don't want it to. What I am worried about is when I give this script to my company (they are using a... (2 Replies)
Discussion started by: Fred Goldman
2 Replies

7. UNIX for Dummies Questions & Answers

Copying one file at a time from one directory to another directory.

Hi All i want to write a script which could copy one file at a time from one directory to another directory. Scenerio: Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs. please help me... (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

8. UNIX for Dummies Questions & Answers

Copying files from one directory to Other

Hi UNIX Gurus, Could please help me out regarding following situation. I am copying some files from one directory to other directotry using following command. cp /var/tmp/*date*.gz /var/tmp/user/ Problem: Once the copy has completed, I need to check whether all the files (including... (3 Replies)
Discussion started by: satishkeshetty
3 Replies

9. UNIX for Dummies Questions & Answers

Copying from CDROM to Directory

Can someone please tell me how to copy a file from a CD that I mounted to a directory in a SCO Unixware system? Thanks in advance (1 Reply)
Discussion started by: George26
1 Replies

10. UNIX for Dummies Questions & Answers

Problems with Copying Directory

Hi, i'm completely new to Unix. I'm trying to copy my "Pictures" folder, and all the folders under it, to a different folder "Photos". So say "Pictures" has a sub folder "2". what happens is "2" is copied to "Photos" like i want it to, but then a sub directory "tmp2" is made which... (3 Replies)
Discussion started by: brudnerx
3 Replies
Login or Register to Ask a Question