![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to count files and get the disk usgae on individual mail folders | phpfreak | Shell Programming and Scripting | 1 | 05-17-2008 05:15 PM |
| two files as a message in mail | ali560045 | Shell Programming and Scripting | 2 | 12-13-2007 02:53 AM |
| Script needed which will send a mail with attachment files | Mar1006 | Shell Programming and Scripting | 4 | 11-24-2007 08:59 AM |
| Automatic Log files to my E-mail. | adel8483 | SUN Solaris | 2 | 04-10-2007 05:10 AM |
| I need a script that script extract info from mail | meravd | Shell Programming and Scripting | 1 | 10-19-2004 12:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Mail Files Script
Please let me know if I'm the right track here, or how it should be done better. Code:
#!/bin/bash
list=`ls -al /some/directory | grep "$1"* | awk '{print $9}'`
for file in $list
do
mail -s "$file" me@email.com < $file
done
My concern is with the list variable. The output is like: Code:
file1 file2 file3 Does the for loop keep each of those filenames in order to loop through? Thoughts? |
|
||||
|
Thanks Shell Life. I'm getting some unwanted results. I've modified the script to look like this: Code:
#!/bin/bash list=`ls /some/directory | grep "$1"*` echo $list echo "starting loop" for file in $list do echo "Mailing" $file #mail -s ....... done I run the code with Code:
./mail.sh file1 Output is: Code:
starting loop So it's not expanding the list variable. |
|
||||
|
Very good, it works that way Shell Life. Is it not possible to pipe within the variable expansion? Edit: or if I have to make it more specific, like if I need to do something like "grep "$1.*-ingress-filter" to restrict the output to the list variable. Edit 2: I've tried the following but it doesnt seem to do the trick. I set list as you specified above, then this: Code:
list2=`echo $base | grep "$1.*-filter"` Ok, I just did: Code:
list=`ls /some/directory/$1*-filter` and that works for me. I'll read up on the variable expansion and pipes. Last edited by earnstaf; 07-05-2007 at 05:40 PM.. |
|
|||||
|
Quote:
The shell expand "$1"* to files starting with the value of $1 in your current directory. Remove the * : Code:
list=`ls /some/directory | grep "$1"` The result is the list of the files in /some/directory which contain $1 in their name. The result given by Shell_Life' solution is the list of the files in /some/directoty which have a their name starting with $1. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|