Ask a Question related to SCO, Design and Development.
-
Nachman Yaakov Ziskind #1
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]awacs@egps.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
-
Maintaining multiple Web Server Route Directories
Is there a way to create a root (home) directory for multiple websites on the same machine (with IIS)? For instance, I would like to use this... -
Multiple directories
I'm wondering if I can set up a client to update her own site using Contribute. The site is for a quarterly magazine. Updates include creating new... -
Using virtual directories for common directories (scripts, images, styles, etc.)
Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of... -
How can I get multiple directories using ftp?
Any idea, what is the right command, in my earlier posting somebody suggested to use mget *, but that is not working. Thanks in advance. -
What directories can be shared between multiple distributions on the same machine??
If I want to install multiple distributions on one machine, there should be some parts that can be shared, such as SWAP, /tmp(if u made it a... -
Nachman Yaakov Ziskind #2
Re: Copying the same file to multiple directories
Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
Following up my own post, I tried:> ... 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!
$ 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]awacs@egps.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
-
Jean-Pierre Radley #3
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
-
justin #4
Re: Copying the same file to multiple directories
> Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
I am assuming that your copy overlayed some existing doc's in the parent>> > ... 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.
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
-
John DuBois #5
Re: Copying the same file to multiple directories
In article <bdsrl6$qoe$1@news.tdl.com>,
justin <justin_robbs@NO_SPAMhotmail.com> wrote:Close, but to avoid problems with filenames that include whitespace, you also>$for F in *
>do
> if [ -d $F ]; then
> cp /path-to-welcome "$F"
> fi
>done
need to quote $F inside of [] (note that this is not true in ksh's [[]] ).
John
--
John DuBois [email]spcecdt@armory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
John DuBois Guest
-
Nachman Yaakov Ziskind #6
Re: Copying the same file to multiple directories
John DuBois wrote (on Wed, Jul 02, 2003 at 12:45:25AM +0000):
Thanks to both Justin and John for replying. I tried Justin's suggestion; it> In article <bdsrl6$qoe$1@news.tdl.com>,
> justin <justin_robbs@NO_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
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]awacs@egps.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
-
tony@aplawrence.com #7
Re: Copying the same file to multiple directories
Bill Vermillion <bv@wjv.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.But why even do that? I'm assuming (and that may be the problem) that>I'd opt for a link to the files - not symbolic but a hard link.
some program somewhere displays the file. Why not just point that program
at one place?
--
[email]tony@aplawrence.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
-
John DuBois #8
Re: Copying the same file to multiple directories
In article <20030701233715.A986@egps.egps.com>,
Nachman Yaakov Ziskind <awacs@egps.com> wrote:Sorry, I don't think I was clear: you don't need to quote variables to avoid>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.
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]spcecdt@armory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
John DuBois Guest



Reply With Quote

