# Copy Script Stops

**URL:** <https://community.unix.com/t/copy-script-stops/370697>\
**Category:** Shell Programming and Scripting\
**Created:** [February 1, 2018, 11:22am UTC](https://community.unix.com/t/copy-script-stops/370697 "2018-02-01T11:22:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stellaman1977](https://community.unix.com/letter_avatar/stellaman1977/32/6_449c533f586939b6e5f246632a46421f.png) [@Stellaman1977](https://community.unix.com/u/Stellaman1977)\
**Post date:** [February 1, 2018, 11:22am UTC](https://community.unix.com/t/copy-script-stops/370697/1 "2018-02-01T11:22:25Z")

</div>

Good Morning,

I have a copy script on Solaris 9 machine that is supposed to copy some files to a NAS using:

```nohighlight
cp -r /dir/dir/ /dir/dir/dir

```

The script doesn't finish. The directory contains user files of which one seems to copy fine, a second was failing until I did a

```nohighlight
chmod -R -777

```

to it. Now, the copy looks the same as far as I can tell, but the directory for the next users never get created and the script seems to stop. Any ideas why? Normally

```nohighlight
crontab

```

runs this script, but I am running it manually from root right now.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_449c533f586939b6e5f246632a46421f.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 1, 2018, 11:53am UTC](https://community.unix.com/t/copy-script-stops/370697/2 "2018-02-01T11:53:44Z")

</div>

This command as written

```nohighlight
chmod -R -777

```

Makes every file + directory (affected by the command) unaccessable. So I do not know what you are trying to do.

Try changing the -777 to 777.

---

<div class="post-metadata">

**Author:** ![Stellaman1977](https://community.unix.com/letter_avatar/stellaman1977/32/6_449c533f586939b6e5f246632a46421f.png) [@Stellaman1977](https://community.unix.com/u/Stellaman1977)\
**Post date:** [February 1, 2018, 4:07pm UTC](https://community.unix.com/t/copy-script-stops/370697/3 "2018-02-01T16:07:13Z")

</div>

Sorry typo there was no -. When I `ls -l` everything looks right.

---

<div class="post-metadata">

**Author:** ![Stellaman1977](https://community.unix.com/letter_avatar/stellaman1977/32/6_449c533f586939b6e5f246632a46421f.png) [@Stellaman1977](https://community.unix.com/u/Stellaman1977)\
**Post date:** [February 5, 2018, 2:37pm UTC](https://community.unix.com/t/copy-script-stops/370697/4 "2018-02-05T14:37:09Z")

</div>

I tried

```nohighlight
cp -r /dir/dir/dir /dir/dir/dir 2>&1 

```

and no error was reported but it stopped at the same user.

---

<div class="post-metadata">

**Author:** ![hicksd8](https://community.unix.com/letter_avatar/hicksd8/32/6_449c533f586939b6e5f246632a46421f.png) [@hicksd8](https://community.unix.com/u/hicksd8)\
**Post date:** [February 6, 2018, 6:23am UTC](https://community.unix.com/t/copy-script-stops/370697/5 "2018-02-06T06:23:16Z")

</div>

Firstly, it is known that:

```nohighlight
# cp -r <whatever>

```

can have problems with special files (device nodes e.g. /dev/\<whatever\>) and also with linked files.

So does including the `-v` switch (verbose) tell you any more?

```nohighlight
# cp -rv <whatever>

```

If no success then try `-R` instead.

```nohighlight
# cp -Rv <whatever>

```

Read the man page for cp to see the difference.

```nohighlight
# man cp

```

If that all fails, then substitute the `cp` for a `find/cpio` combination to copy your directory tree:

```nohighlight
# cd /dir/dir/<top of tree to be copied>
# find . -depth -print|cpio -puvdm <target directory>

```

Note: In the above the \<target directory\> MUST already exist before the command is issued.

See if that does the job. Do let us all know the outcome.

---

<div class="post-metadata">

**Author:** ![bakunin](https://community.unix.com/letter_avatar/bakunin/32/6_449c533f586939b6e5f246632a46421f.png) [@bakunin](https://community.unix.com/u/bakunin)\
**Post date:** [February 6, 2018, 8:02am UTC](https://community.unix.com/t/copy-script-stops/370697/6 "2018-02-06T08:02:41Z")

</div>

Under which user account did you run the script? If it was not `root` this might have been the problem.

Furthermore, to copy a (sub-)tree recursively it is generally better to use `tar` instead of `cp -r` :

```nohighlight
cd /path/to/source ; tar -cf - * | (cd /path/to/target ; tar xf -)

```

will copy all files and directories in `/path/to/source` to `/path/to/target` AND it will preserve all filemodes and ownership properties.

I hope this helps.

bakunin

---

<div class="post-metadata">

**Author:** ![Stellaman1977](https://community.unix.com/letter_avatar/stellaman1977/32/6_449c533f586939b6e5f246632a46421f.png) [@Stellaman1977](https://community.unix.com/u/Stellaman1977)\
**Post date:** [February 6, 2018, 12:48pm UTC](https://community.unix.com/t/copy-script-stops/370697/7 "2018-02-06T12:48:30Z")

</div>

Thanks everyone.. Its working now.

```nohighlight
cp -R

```

not

```nohighlight
cp -r

```

I'm not piping anything so I'm not sure why it works.. but it works.

I'll read up on tar anyway- I've never used it.
