Script Assist


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script Assist
# 1  
Old 03-28-2008
Bug Script Assist

Hello all I am new and I had a question that I was hoping you could answer.

I am using mutt on a directory in this directory will be pdf files named 001.pdf , 002.pdf and so on. I need a script that can read the filename and associate that with a user like so :

if 001.pdf exists then email 001.pdf ( using mutt ) to user1 and then delete 001.pdf and continue until directory is empty. each file name will be associated with a user code and email address.

001 = user1
002 = user2

is there an easy way to accomplish this task ?
# 2  
Old 03-28-2008
Code:
ls *.pdf |
sed -n 's/^\(0*\(\[1-9][0-9]*\)\.pdf\)/\1 user\2/p' |
while read file user; do
  : use your imagination here
done

# 3  
Old 03-28-2008
era ,

Ive tried your reply and cant seem to get it to work. my other question was how is it supposed to identify the user based on the filename in your script ?


I want each filename to reference a user like 001=user1@domain via some sort of variable.


so when it attaches the file to an email it will know who to send it to .

mutt -s "userfile" -a 001.pdf user1@domain < msg-body

and then delete the file from the directory after it has been sent. and continue this step for each file until the directory is empty.

and thanks for your reply.
# 4  
Old 03-28-2008
I meant to ask about how to map file names to users. Your example made it seem like the mapping would be trivial but I really meant to ask about that. It complicates matters somewhat.

So, you mean that in reality, 001.pdf should go to era@example.com and 002.pdf should go to n00by@unix.com and so forth?

Do you have this mapping table in some form somewhere? A text file, for example?

Code:
while read file user; do
  test -e "$file" || continue
  # continue to use your imagination here.
  # for example, start populating this with just
  echo file $file, user $user"
  # to see what's going on
done< pdf-to-user.txt

... assuming the file name to user mapping file is a space-delimited file called pdf-to-user.txt
# 5  
Old 03-28-2008
a txt file would make more sense in my case for the users.
but yes you have the basic idea of things. each file name goes off to a different user.
# 6  
Old 03-28-2008
ok so I created the txt file and it is in this format and called it pdf-to-user.txt ( im sure the following is extremely wrong because it isnt doing anything ( i do mean wrong on my part for not fully understanding) . the files are all located in a directory called /home/linuxguy/pdf but it doesnt seem to be reading anything how do I specify this ?

001 = linuxguy
002 = user2
##########
the script is as follows :
domain = unix.com
mail = mutt -s "mail" -a $file $user@domain

while read file user; do
test -e "$file" || continue || $mail
# continue to use your imagination here.
# for example, start populating this with just
echo file $file, user $user"
# to see what's going on
done< pdf-to-user.txt
# 7  
Old 03-28-2008
That last line says where it reads the information from, after the redirection operator. I assumed you would have "pdf-to-user.txt" in the current directory but simply update the path name if it's somewhere else.

You can't put the variables in the mail command's definition because they will get their values only inside the loop. Also you need @$domain with a dollar sign.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Red Hat

assist me in UNIX scripting

hi ... i want to monitor the httpd service whether its online or offline.. if httpd service goes offline/stopped then i need to get alert to my mail. how to do construct this script.. myself using RHEL4 ... (1 Reply)
Discussion started by: sriniv666
1 Replies

2. Shell Programming and Scripting

In need of assist....

How would i take the output of a file dump it into another file while at the same time sorting it? this is my script..simple i know!? echo "Enter the file log you wish to use. : " read file awk '{print $1,$2,$4,$5}' $file >> list Im trying to dump it into that list file and sort it at... (6 Replies)
Discussion started by: jspinal
6 Replies

3. Shell Programming and Scripting

Need of a Parsing Script Assist...

Im trying to find a script that will pull ip addresses along with the date and time sort it by ip addresses and output it to a file... As a newbie to scripting im kinda stumped here...and suggestions? (2 Replies)
Discussion started by: jspinal
2 Replies

4. UNIX for Dummies Questions & Answers

Please Assist

I try taip this script below...but i have got error.The error message is Input read error..Anybody can see whether my script have problem.Below this is my script: #!/bin/sh filename=test.txt vi $filename <<EndOfCommands i This file was created automatically from a shell script ^ (1 Reply)
Discussion started by: mastercar
1 Replies

5. Shell Programming and Scripting

Editing a ksh script > Please assist!

I am trying to edit a script that contains the following: /DBA/general/sh/rman_backup.ksh -d PROD2 -l 1 I am trying to add a logic in the script such that if /DBA/general/sh/rman_backup.ksh does not exists, then the script would return an error code of 1. Otherwise, the script continues... (4 Replies)
Discussion started by: ora_umair
4 Replies

6. HP-UX

Assist me in doing certification please

Hi Everybody, Iam new to the unix world but interested a lot to know about unix. i want to do a certification course in unix so can anybody please suggest me what course can i do for unix adminstration and what books do i have to refer to. Thanks in Advance. (5 Replies)
Discussion started by: ajazshariff
5 Replies

7. Programming

could some assist please

i was searching on the net have found a couple of sample programs and was wondering if some could tell me what they do cheers. main() { printf("Executing ls\n"); execl("/bin/ls","ls","-l", (char *)0); perror("execl failed to run ls"); exit(1); } main() { int i; i =... (5 Replies)
Discussion started by: ruffenator
5 Replies
Login or Register to Ask a Question