Help on Simple shell that look for a file type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on Simple shell that look for a file type
# 1  
Old 10-06-2003
Help on Simple shell that look for a file type

Hello Everyone,

I got a simple question. I'm trying to write a shell that looks for a file that arived ftp area and keeps looking until it find it.

Quote:
#!/bin/ksh

for file in /usr/users/ftp/wmdaten/test*

do if [ -f $file ]

then

continue

fi

/usr/local/bin/wmdaten.sh

done


It should look for the file that begins with test and then when it finds it. It starts the wmdaten.sh shell. All i got is that it runs through starts the shell even when test file is not there. It would be great if someone could show what i did wrong.

Thanks Pete
# 2  
Old 10-06-2003
............

i would do such searching loops with "while"

greetings Preßy
# 3  
Old 10-06-2003
Your approach does not seem quite right to me.

Since your wmdatem.sh script does not take any parameters I assume it knows what to do with the files in the directory.

You may simply be better off counting the number of files which happen to match the name you are looking for. Something like

COUNT=`ls /usr/users/ftp/wmdaten/test* | wc -l`

Continue to poll the ftp directory while the file count is 0. When the count is greater than zero break out the loop and call the script?

MBB
# 4  
Old 10-06-2003
Is this what you're trying to do? Just a minor change to your existing code...
Code:
#!/bin/ksh
for file in /usr/users/ftp/wmdaten/test*
do
 if [ -f $file ]
 then
  /usr/local/bin/wmdaten.sh
 fi
done

# 5  
Old 10-06-2003
Geez, everyone's in such a hurry these days

Scripts like these will put considerable load on system. Even a "sleep 1" inserted into the loop will help a lot.
# 6  
Old 10-07-2003
Computer

Thanks oombera,


Thats what i was looking for. I just got finished with my shell programing course from Sun, I was working on this. I know its not much but just learning.

And Perderabo thanks too. I know its a large load for the machine but its only running for max 10 min. and when no users are using the system.

Thanks again to everyone... Smilie

Pete
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Shell script to find file type

1. The problem statement, all variables and given/known data: Write a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an... (4 Replies)
Discussion started by: kwatt019
4 Replies

2. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

3. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

4. Shell Programming and Scripting

shell type.. /bin/uvalid?

Hi, I gave a command echo $SHELL --> To find out the shell I'm using, which gave me the below output echo $SHELL /bin/uvalid what does it mean? Please use code tags when posting data and code samples, thank you. (1 Reply)
Discussion started by: dnam9917
1 Replies

5. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

6. UNIX for Dummies Questions & Answers

Assistance with shell script to check file type and move to a folder.

Hi, Below is some code that I would like to implement however I am getting these errors: (what I am attempting to do is to check if a zip file has ascii files and if ascii and not binary then move the ascii files to a folder. some of the files are in xml format but are ascii and i will be moving... (0 Replies)
Discussion started by: bwcberb
0 Replies

7. UNIX for Advanced & Expert Users

changing shell type from sh to ksh

Could someone please advise, what's the best way to changing the shell type from sh to ksh. When I login into a unix server it takes you directly to sh, is there a way of amending the .profile to use ksh instead. Or is there some other way ? Ideally it would be good to be done from the login... (10 Replies)
Discussion started by: venhart
10 Replies

8. Shell Programming and Scripting

Need a simple file based utilty for shell scripts

Hello, I'm wondering if you may know of a simple file based UNIX utility that can be used to store and retrieve values on a flat file, let's say i have a file called "kru", i'd like to be able to specify a request like: while(....) if ; then kru.fld2 = $rec_cnt kru.fld3 =... (4 Replies)
Discussion started by: bobk544
4 Replies

9. UNIX for Dummies Questions & Answers

how to display the shell type

hello, I was wondering what is the command to display the shell type? much thanks (3 Replies)
Discussion started by: yipster
3 Replies

10. Shell Programming and Scripting

how to identify the type of shell using comands..

Dear friends, please tell me how to identify the type of the shell (whether cShell, kshell or anything else) please tell me the command. waiting for ur reply.... regards, swamymns (2 Replies)
Discussion started by: swamymns
2 Replies
Login or Register to Ask a Question