Script Assist


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script Assist
# 8  
Old 03-28-2008
ok heres what happened

when trying to execute this script :

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


nothing happens. is the supposed to be an open quote at user ? I was also wondering where does the script know the values for $file and $user ?

I modified it and ended up telling it instead of file to use LINE and all it did was print out the list line by line. for now I want to focus on trying to get the script to echo $filename and $user . the text file is basically space separated and it starts with filename 001 username


Thanks for the help .
# 9  
Old 03-28-2008
Yeah, sorry, the opening quote is missing after the echo.

It reads the values from the file. I guess you can guess what "while" does. "read" reads a line of input into the named variable(s) splitting on whitespace. The redirection down at the end of the loop (after "done") says where to get this input from. Without the redirection it would wait for you to type in this information; you could try that just to get a feel for it. (Press ctrl-D when you think you have typed in enough lines.)

The file format should be unadorned, two fields exactly per line, the first is the file name and the second is the corresponding user name. If you want to factor out the ".pdf" extension then that's possible, but I didn't do it.

The "test" checks for the file in the current directory; if it does not exist, the rest of the loop is skipped for this file and user, and the next iteration of the loop is started.
# 10  
Old 03-28-2008
heres what Ive changed and I cant seem to get echo to show any data,.

#!/bin/bash

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

I run this script and nothing happens.
# 11  
Old 03-28-2008
Create one of the files which it expects to find and you should see, well, something. (I was going to write "sparks will fly" but this is really very pedestrian.)
# 12  
Old 03-28-2008
I currently have a directory with 8 pdfs in it. I also have the script and the user text file in the same directory. should there be anything else ? Im running this on CentOS via BASH if that matters.

but Im not getting any output.
# 13  
Old 03-28-2008
Move the echo up before the test to see what is being read and examined.
# 14  
Old 03-28-2008
AHA .. now were getting somewhere. result is .

file 001, user blue
file 002, user green
file 003, user red
file 004, user brown
file 005, user orange


there are 8 pdf files in the directory however it read that data from the user file.

now if I can get it read the directory and pull the filenames from there I should be good. is there any way we can talk outside of the post ? I have an offer for you.
 
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