[SlugBug] shell script help (fwd)

Chris J cej at nightwolf.org.uk
Thu Aug 7 18:56:44 BST 2003


*slap* I will remember to do reply-all eventually ...

------- Forwarded Message


And Lo! The Great Prophet Bill Best uttered these words of wisdom:
> 
> sorry for the lame-ness, but i would know like to produce a report of 
> these file duplications and then have that emailed to me.
> 
> for FILE in $(ls directory1/*); do
>  for FILE2 in $(ls directory2/*); do
>    cmp -s $FILE $FILE2
>     [ $? -eq 0 ] && echo $FILE $FILE2 >> same.txt
>     done
> done
>
> how do i get same.txt to be emailed to me?


As Jean-Michel mentioned, cat some.file | mail my at email.address will do the 
job, however you also have another possibility:

	for FILE in $(ls directory1/*); do
	    for FILE2 in $(ls directory2/*); do
	        cmp -s $FILE $FILE2
	        [ $? -eq 0 ] && echo $FILE $FILE2
	    done
	done 2>&1 | mail -s 'some subject' some at email.address.here

is one possiblity (no logfile, instead the results are mailed straight to
you), or if you also want to keep a log file, add tee to the pipeline:

	for FILE in $(ls directory1/*); do
	    for FILE2 in $(ls directory2/*); do
	        cmp -s $FILE $FILE2
	        [ $? -eq 0 ] && echo $FILE $FILE2
	    done
	done 2>&1 | tee mylogfile.txt | mail -s 'some subject' some at email.address.here

The 2>&1 ensures that if you have anything thrown to stderr, that will be
logged as well. Also, if you want logfile appended to each time it runs, 
rather than overwritten, then change the tee invocation to "tee -a".

There's all sorts of other stuff you can do then in that output pipeline :)

Chris...


- -- 
\ Chris Johnson           \ NP: Catatonia - 08. Why I Can't Stand One Night 
 \ cej at nightwolf.org.uk    ~-----,  Stands 
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------, 
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____



------- End of Forwarded Message


-- 
\ Chris Johnson           \ NP: Catatonia - 09. Part Of The Furniture
 \ cej at nightwolf.org.uk    ~-----,   
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------, 
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____





More information about the SlugBug mailing list