LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 04-03-2008, 06:05 AM   #1
decartes
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Rep: Reputation: 0
Copy single file to multiple locations - What am I doing wrong


Hi

I have a little server running qmail/plesk . The problem is my ISP wont support Spamassassin due to load issues on the host server and I cannot afford to migrate to a root server (using VMWARE at the mo).

I have spamassassin installed manually but also need to use plesk for adding domains and I got it working. Problem is it is set up by default to rewrite_headers and accept the message. I need to reject it via the .qmail files.

I have one .qmail file and I need to copy it over every users .qmail file. Here is what I am trying.

Code:
cp ./.qmail /var/qmail/mailnames/*/.qmail
Where * can be any domain.

However the cp command complains that /var/qmail/mailnames/*/.qmail is not a directory. I already know that and want to overwrite the file. if I omit the .qmail file and do cp ./.qmail /var/qmail/mailnames/*/ it returns a message like 'Omitting directory example.com/ ....'

What am I doing wrong. All I want to do is copy one file to multiple folders which are all level one sub-folders of a parent folder we know the path to.

By the way ln -s gives exactly the same error

Thanks in advance
 
Old 04-03-2008, 07:14 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
 
Old 04-03-2008, 07:30 AM   #3
decartes
LQ Newbie
 
Registered: Jul 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Excellent, thanks for the quick response. Works a treat. See what you mean about refining. Nearly orverwrote my quota files.

Thanks again, this is the best tip I've had for ages. I badly need to develop my bash scripting skills, do you know of any resources?



Quote:
Originally Posted by colucix View Post
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
 
Old 04-22-2008, 06:17 PM   #4
kaelthas
Member
 
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30

Rep: Reputation: 15
Is there a way to get this to work with directories that have spaces in their names? This is a great solution otherwise. Whenever I try this, it copies my file into directories with no spaces just fine, but if the directory has a space in the name, i end up with a file named the first part of the directory name in the directory above it.

Quote:
Originally Posted by colucix View Post
The problem is that when the wildcard is expanded the command line looks like
Code:
cp ./.qmail /var/qmail/mailnames/user1/.qmail /var/qmail/mailnames/user2/.qmail /var/qmail/mailnames/user2/.qmail
and the error message tells you that when you have multiple sources the last entry in the command line should be a destination directory. You cannot copy a single source file to multiple destination, whereas you can copy multiple sources to one destination. You can solve this by a simple for loop:
Code:
# for dest in /var/qmail/mailnames/*
> do
> cp ./.qmail $dest
> done
but first check that /var/qmail/mailnames/* expands to the directories you want to copy the file into. If it happens that you have a file in /var/qmail/mailnames, it will overwritten by .qmail. In this case you can refine the criteria as in
Code:
# for dest in $(find /var/qmail/mailnames -mindepth 1 -type d)
> do
> cp ./.qmail $dest
> done
 
Old 04-22-2008, 06:25 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
iirc, you need to change the Internal Field Separator (IFS) shell var. By default it's space or tab or newline, and you want to reduce it to just a newline inside the shell script.
At the top put

IFS="
"
That's a newline (rtn) with surrounding quotes. This new definition will revert to normal when the shell prog exits.
Here's a good tutorial: http://rute.2038bug.com/index.html.gz , also http://www.tldp.org/LDP/abs/html/ & http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
Old 04-22-2008, 06:41 PM   #6
lcole
Member
 
Registered: Aug 2003
Location: Oregon
Distribution: Ubuntu
Posts: 50

Rep: Reputation: 18
does this help?

1) link to Advanced Bash Scripting Guide:
http://tldp.org/LDP/abs/html/

2)
[lcole@harley ~]$ find ~/"space in name" -mindepth 1 -type d
/home/lcole/space in name/a
/home/lcole/space in name/b
/home/lcole/space in name/a b
 
Old 04-22-2008, 08:15 PM   #7
kaelthas
Member
 
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30

Rep: Reputation: 15
thank you for the fast responses some new things to try, i'll keep you posted.
 
Old 04-26-2008, 04:09 PM   #8
kaelthas
Member
 
Registered: Jun 2007
Location: Troy, Michigan, USA
Distribution: Gentoo
Posts: 30

Rep: Reputation: 15
just to update, setting IFS worked great, thanks

Quote:
Originally Posted by kaelthas View Post
thank you for the fast responses some new things to try, i'll keep you posted.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying a single file to multiple directories quest49 Linux - Software 6 12-04-2006 08:07 AM
How to Unrar/unzip multiple archives at once containing a single file? SentralOrigin Linux - Software 11 11-30-2006 05:57 PM
Adding Multiple Files In A Single Gz File onacorpuscle Linux - Newbie 3 08-31-2006 03:18 AM
Compiling multiple .c file using single command in makefile vipulc Linux - General 2 03-18-2006 11:49 PM
Copying a single file to multiple directories tgolly Linux - Newbie 3 04-26-2004 03:47 PM


All times are GMT -5. The time now is 01:24 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration