I am trying to move a group of sendmail queue files into a special area and am developing s script to assist. The manual steps are: # Identify which messages to move mailq -qR<domain> > file1 # Select only lines with message ID strings grep '^[[:alpha:]][[:alnum:]]\{13\}' file1 > file2 # extract only the messages ID cut -b -14 file2 > file3 # prepend '*' to message IDs sed "s/^/\*/" file3 > file4 All of this works the way that I expect. What I now want to do is to mv all of the related files listed in file4 in the form "*messageid" to another directory. Using xargs I expected (naively) that the following construction would work: cat file4 | xargs mv /var/spool/mqueue/'{}' \ /var/spool/mqueue/offline (note that in the original this is all one line.) However, when I do this I get the error: mv: when moving multiple files, last argument must be a directory Try `mv --help' for more information. There is obviously something about xargs that I do not understand. In my imagination I see this xargs construction expanding to this: mv /var/spool/mqueue/*messageid1 /var/spool/mqueue/offline mv /var/spool/mqueue/*messageid2 /var/spool/mqueue/offline . . . mv /var/spool/mqueue/*messageidn /var/spool/mqueue/offline so that the qf and df files for each message are moved into the subdirectory offline. But this is obviously incorrect. Can anyone here point out to me what my misunderstanding is and how to get this to work? If this is not the forum for this kind of question then can someone with more experience point me to a mailing list that would be more suitable? Regards, JIm -- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3
On Tue, 8 Feb 2005, James B. Byrne wrote:> I am trying to move a group of sendmail queue files into a special > area and am developing s script to assist. The manual steps are: > > # Identify which messages to move > mailq -qR<domain> > file1 > > # Select only lines with message ID strings > grep '^[[:alpha:]][[:alnum:]]\{13\}' file1 > file2 > > # extract only the messages ID > cut -b -14 file2 > file3 > > # prepend '*' to message IDs > sed "s/^/\*/" file3 > file4 > > All of this works the way that I expect. What I now want to do is > to mv all of the related files listed in file4 in the form > "*messageid" to another directory. Using xargs I expected > (naively) that the following construction would work: > > cat file4 | xargs mv /var/spool/mqueue/'{}' \ > /var/spool/mqueue/offline > > (note that in the original this is all one line.) > > However, when I do this I get the error: > mv: when moving multiple files, last argument must be a directory > Try `mv --help' for more information. > > There is obviously something about xargs that I do not understand. > In my imagination I see this xargs construction expanding to this: > > mv /var/spool/mqueue/*messageid1 /var/spool/mqueue/offline > mv /var/spool/mqueue/*messageid2 /var/spool/mqueue/offline > . > . > . > mv /var/spool/mqueue/*messageidn /var/spool/mqueue/offline > > so that the qf and df files for each message are moved into the > subdirectory offline. But this is obviously incorrect. Can anyone > here point out to me what my misunderstanding is and how to get > this to work? If this is not the forum for this kind of question > then can someone with more experience point me to a mailing list > that would be more suitable?Compare this: echo -e "file1\nfile2\nfile3" | xargs echo '{}' blah with: echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah What you require is -i to make '{}' work. xargs by default appends the input as a list of arguments. The manpage says: --replace[=replace-str], -I replace-str, -i[replace-str] Replace occurences of replace-str in the initial arguments with names read from standard input. Also, unquoted blanks do not terminate argu- ments. If replace-str is omitted, it defaults to "{}" (like for 'find -exec'). Implies -x and -L 1. Kind regards, -- dag wieers, dag at wieers.com, http://dag.wieers.com/ -- [all I want is a warm bed and a kind word and unlimited power]
James B. Byrne wrote:> > cat file4 | xargs mv /var/spool/mqueue/'{}' \ > /var/spool/mqueue/offlineTo provide an alternate way (thanks Dag, learned a new xargs switch :) ) I would instintively write this bash command as: while read filename && [[ "$filename" != end ]] do mv -f "/var/spool/mqueue/$filename" /var/spool/mqueue/offline/ done < "/path/to/file4" hth, -te -- Troy Engel | Systems Engineer Fluid, Inc | http://www.fluid.com
On 8 Feb 2005 at 23:14, Dag Wieers wrote:> Compare this: > > echo -e "file1\nfile2\nfile3" | xargs echo '{}' blah > > with: > > echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blahThank you for the advice on the -i switch. I had tried this earlier. With the -i '{}' argument added then this is the result: # ll -d ./mqueue/offline drwxr-xr-x 2 root root 4096 Feb 8 14:03 ./mqueue/offline # # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline xargs: {}: No such file or directory # # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline/ xargs: {}: No such file or directory # # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline ./mqueue/'{}' xargs: {}: No such file or directory # # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline/ ./mqueue/'{}' xargs: {}: No such file or directory # P.S. Also, thank you very much for the depository that you run. I use several of your packages. Regards, Jim -- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3
Just a note that I caught and corrected the syntax error on my last example and that correcting it does not change the result at all. # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline/ ./mqueue/'{}' vice # cat workmv | xargs -i '{}' --Target-Directory=./mqueue/offline/ mv ./mqueue/'{}' both give xargs: {}: No such file or directory Regards, Jim -- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3
On 8 Feb 2005 at 15:15, James B. Byrne wrote:> I am trying to move a group of sendmail queue files into a special > area and am developing s script to assist. The manual steps are:This doesn't answer your question directly, and it's a bit late given the rest of the thread, but for future reference you might want to have a look at "qtool.pl" (included in the contrib/ directory with the Sendmail source). It pretty much does everything you need, and has the advantage of using Sendmail's file locking method to avoid conflicts with a running sendmail queue-running process. Something like the following will do what you need: #!/bin/bash OLQUEUE=/var/spool/mqueue/offline QUEUE=/var/spool/mqueue qtool.pl -e '$msg{recipient} ~= "<domain>"' $OLQUEUE $QUEUE ---- Nels Lindquist <*> Information Systems Manager Morningstar Air Express Inc.
On 10 Feb 2005 at 11:37, Nels Lindquist wrote:> This doesn't answer your question directly, and it's a bit late > given the rest of the thread, but for future reference you might > want to have a look at "qtool.pl" (included in the contrib/ > directory with the Sendmail source).That is exactly what I was trying to find before I gave up and decided to roll my own. Now the odd thing is, I googled 'sendmail queue manager script' and similar constructs and came up empty on anything like this. As I do not have the sendmail src packages installed I will see if I can locate this tool on the web somewhere. Thank you very much for the info. This will make future occurrences much easier to deal with. I find it remarkable that this tool is not mentioned in the Bat book however. Regards, Jim -- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3