Professional Web Applications Themes

Copying the same file to multiple directories - SCO

.... say I wanted to copy a file, call it "welcome", to every user's home directory. I know that all the folders live in /usr; thus /usr/first, /usr/second, ... /usr/thousand-and-twenty-two, ... IOW, I want to automate: $ cd /usr $ cp /path-to-welcome first $ cp /path-to-welcome second $ cp /path-to-welcome third $ cp /path-to-welcome fourth etc. What's the nicest/easiest way to do this? SCO 506. Thanks! -- _________________________________________ Nachman Yaakov Ziskind, EA, LLM [email]awacsegps.com[/email] Attorney and Counselor-at-Law [url]http://yankel.com[/url] Economic Group Pension Services [url]http://egps.com[/url] Actuaries and Employee Benefit Consultants...

  1. #1

    Default Copying the same file to multiple directories

    .... say I wanted to copy a file, call it "welcome", to every user's home
    directory. I know that all the folders live in /usr; thus /usr/first,
    /usr/second, ... /usr/thousand-and-twenty-two, ...

    IOW, I want to automate:

    $ cd /usr
    $ cp /path-to-welcome first
    $ cp /path-to-welcome second
    $ cp /path-to-welcome third
    $ cp /path-to-welcome fourth

    etc.

    What's the nicest/easiest way to do this? SCO 506.

    Thanks!

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacsegps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  2. #2

    Default Re: Copying the same file to multiple directories

    Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    > ... say I wanted to copy a file, call it "welcome", to every user's home
    > directory. I know that all the folders live in /usr; thus /usr/first,
    > /usr/second, ... /usr/thousand-and-twenty-two, ...
    >
    > IOW, I want to automate:
    >
    > $ cd /usr
    > $ cp /path-to-welcome first
    > $ cp /path-to-welcome second
    > $ cp /path-to-welcome third
    > $ cp /path-to-welcome fourth
    >
    > etc.
    >
    > What's the nicest/easiest way to do this? SCO 506.
    >
    > Thanks!
    Following up my own post, I tried:

    $ for F in *
    do
    copy /path-to-welcome $F
    done

    which worked somewhat, except:

    a) It destroyed two (of ten or so) .docs, rendering them zero bytes.

    b) It didn't copy to directories with spaces in them, giving errors:

    cp: target (Enterprises) must be a directory
    Usage: cp [-fip] source_file target_file
    cp [-r|-R][-fip] source_file... target_file

    Thanks, again.

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacsegps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  3. #3

    Default Re: Copying the same file to multiple directories

    Nachman Yaakov Ziskind typed (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    | ... say I wanted to copy a file, call it "welcome", to every user's home
    | directory. I know that all the folders live in /usr; thus /usr/first,
    | /usr/second, ... /usr/thousand-and-twenty-two, ...
    |
    | IOW, I want to automate:
    |
    | $ cd /usr
    | $ cp /path-to-welcome first
    | $ cp /path-to-welcome second
    | $ cp /path-to-welcome third
    | $ cp /path-to-welcome fourth
    |
    | etc.
    |
    | What's the nicest/easiest way to do this? SCO 506.


    #!/bin/ksh
    for D in `awk -F: '$3 >= 200 { print $6 }' /etc/passwd`
    do
    [[ -f $D/.profile || -f $D/.login ]] && cp /path-to-welcome $D
    done

    Slight aside: 5.0.7 does not place users in /usr by default, but in /u.
    Take the trouble to move them all there now, it will make your eventual
    upgrade far less annoying. The script I just wrote gives you the bare
    bones for another script to both edit /etc/passwd and move the home
    directories.

    --
    JP
    Jean-Pierre Radley Guest

  4. #4

    Default Re: Copying the same file to multiple directories

    > Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    > > ... say I wanted to copy a file, call it "welcome", to every user's home
    > > directory. I know that all the folders live in /usr; thus /usr/first,
    > > /usr/second, ... /usr/thousand-and-twenty-two, ...
    > >
    > > IOW, I want to automate:
    > >
    > > $ cd /usr
    > > $ cp /path-to-welcome first
    > > $ cp /path-to-welcome second
    > > $ cp /path-to-welcome third
    > > $ cp /path-to-welcome fourth
    > >
    > > etc.
    > >
    > > What's the nicest/easiest way to do this? SCO 506.
    > >
    > > Thanks!
    >
    > Following up my own post, I tried:
    >
    > $ for F in *
    > do
    > copy /path-to-welcome $F
    > done
    >
    > which worked somewhat, except:
    >
    > a) It destroyed two (of ten or so) .docs, rendering them zero bytes.
    I am assuming that your copy overlayed some existing doc's in the parent
    directory. I realize I am stating the obvious but just wanted to clarify.
    Here is a script that would at least eliminate that problem.

    $for F in *
    do
    if [ -d $F ]; then
    cp /path-to-welcome "$F"
    fi
    done

    I ran a limited test and it appeared to work. I hope this helps as this is
    about the extent of my shell programming knowledge.

    justin



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.495 / Virus Database: 294 - Release Date: 6/30/03


    justin Guest

  5. #5

    Default Re: Copying the same file to multiple directories

    In article <bdsrl6$qoe$1news.tdl.com>,
    justin <justin_robbsNO_SPAMhotmail.com> wrote:
    >$for F in *
    >do
    > if [ -d $F ]; then
    > cp /path-to-welcome "$F"
    > fi
    >done
    Close, but to avoid problems with filenames that include whitespace, you also
    need to quote $F inside of [] (note that this is not true in ksh's [[]] ).

    John
    --
    John DuBois [email]spcecdtarmory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
    John DuBois Guest

  6. #6

    Default Re: Copying the same file to multiple directories

    John DuBois wrote (on Wed, Jul 02, 2003 at 12:45:25AM +0000):
    > In article <bdsrl6$qoe$1news.tdl.com>,
    > justin <justin_robbsNO_SPAMhotmail.com> wrote:
    > >$for F in *
    > >do
    > > if [ -d $F ]; then
    > > cp /path-to-welcome "$F"
    > > fi
    > >done
    >
    > Close, but to avoid problems with filenames that include whitespace, you also
    > need to quote $F inside of [] (note that this is not true in ksh's [[]] ).
    >
    > John
    Thanks to both Justin and John for replying. I tried Justin's suggestion; it
    worked on the directory names without spaces, as well as *some of* the ones
    with spaces (have no clue why). Note that I was using ksh.

    Then I tried replacing the first $F with sh:

    if [ -d "$F" ]; then

    And it worked. Woo-hoo!

    Time to sacrifice a virgin by the altar of Unix.

    NYZ

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacsegps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  7. #7

    Default Re: Copying the same file to multiple directories

    Bill Vermillion <bvwjv.comremove> wrote:
    >To my way of thinking about it the easiest way is NOT to copy
    >the file to all those user files - particularly if you do
    >have 1022 or more users as the folders indicate.

    Exactly my immediate first thought.
    >1022 files of only 20 bytes [for an exmaple] will occupy a minimum
    >of 1MB - as each file takes two disk blocks.
    >If these are typical welcome messages then the user never needs to
    >modify them, or even has permission to do so.
    >I'd opt for a link to the files - not symbolic but a hard link.
    But why even do that? I'm assuming (and that may be the problem) that
    some program somewhere displays the file. Why not just point that program
    at one place?

    --
    [email]tonyaplawrence.com[/email] Unix/Linux resources: [url]http://aplawrence.com[/url]
    Inexpensive phone/email support
    Free SCO Skills Test: [url]http://pcunix.com/skilltests.html[/url]
    tony@aplawrence.com Guest

  8. #8

    Default Re: Copying the same file to multiple directories

    In article <20030701233715.A986egps.egps.com>,
    Nachman Yaakov Ziskind <awacsegps.com> wrote:
    >John DuBois wrote (on Wed, Jul 02, 2003 at 12:45:25AM +0000):
    >> Close, but to avoid problems with filenames that include whitespace, you also
    >> need to quote $F inside of [] (note that this is not true in ksh's [[]] ).
    >
    >Thanks to both Justin and John for replying. I tried Justin's suggestion; it
    >worked on the directory names without spaces, as well as *some of* the ones
    >with spaces (have no clue why). Note that I was using ksh.
    Sorry, I don't think I was clear: you don't need to quote variables to avoid
    field splitting and globbing inside of ksh's [[ ]] operators, which are
    alternatives to the [ ] that exist in both sh and sh. In ksh you can do:

    if [[ -d $F ]]; then ...

    while even in ksh you do need to do:

    if [ -d "$F" ]; then ...

    This is because [ in ksh is emulating an external program called '[', and so
    field splitting and globbing must be performed as they are for all other
    external programs. [[ ]] are new, explicitly built-in keywords that have new
    behavior defined for them. For non-arithmetic operations, I use them in
    preference to [] in ksh programs; in addition to avoiding the need for quoting
    in the above cases, they allow for pattern matching, more sensible boolean
    expressions, etc. For arithmetic operations, I use (()), which allow for most
    C expressions and then some.

    John
    --
    John DuBois [email]spcecdtarmory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
    John DuBois Guest

Similar Threads

  1. Maintaining multiple Web Server Route Directories
    By John L. in forum ASP Components
    Replies: 2
    Last Post: February 28th, 10:39 AM
  2. Multiple directories
    By KKreps in forum Macromedia Contribute General Discussion
    Replies: 0
    Last Post: April 16th, 02:41 AM
  3. copying php file
    By Ellyrion in forum PHP Development
    Replies: 2
    Last Post: December 14th, 12:19 AM
  4. How can I get multiple directories using ftp?
    By Santa in forum Linux Setup, Configuration & Administration
    Replies: 3
    Last Post: July 18th, 08:50 AM
  5. Replies: 7
    Last Post: July 7th, 05:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139