Loop SCript


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Loop SCript
# 1  
Old 11-24-2015
Loop SCript

Hi,

I am newer to UNIX scripting. Here is what I am trying to accomplish:

I want to log a timestamp and a row count for a spcific file, out to another file.

Below is my script. WhenI run it, it says that line 6 is missing a ']' which I don't see how, and then echos File Does Not Exist (which the file does exist and is at 777).

Any help on this would be grealy appreciated - I don't have the best tools to troubleshoot and debug so also if there is a easy to use tool that you could suggest please do so, I don't like asking others to debug my code.

Script:


Code:
#!/bin/bash
a=0 
while [ $a -lt 10 ]
do
if [ -f /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing]
then
   echo "File exists"
wc -k /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing |sed -e "s/^/$(date)/">>/pr/datastage/AUST/workarea/LargeFileForTesting_AUST.txt_Processing_Row_Count
else
   echo "File does not exists"
   break
   a=1
fi
done


Last edited by Don Cragun; 11-24-2015 at 03:57 PM.. Reason: Add CODE tags.
# 2  
Old 11-24-2015
Code:
if [ -f /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing ]

The problem you are reporting is due to a missing space between Processing and ]
However, you might have another problem. You never increase the loop counter so it will never stop looping unless that the file does not exist.
# 3  
Old 11-24-2015
Thanks, I will look into that and remove the space!
Correct, I am depending on the loop to break when the file doesn't exist. The file will be moved after processing is completed and then it will no longer exist.
Thanks for your reply and assitance.
# 4  
Old 11-24-2015
Quote:
Originally Posted by eanolan
Thanks, I will look into that and remove the space!
Correct, I am depending on the loop to break when the file doesn't exist. The file will be moved after processing is completed and then it will no longer exist.
Thanks for your reply and assitance.
I think you misunderstood me. You do not have a space, and there should be one as I show in the highlighted portion I posted.
Also, entering the loop, if the /pr/datastage/AUST/outputLargeFileForTesting_AUST.txt_Processing exists once, the loop will be a forever loop, since you are not increasing the counter to ever become 10.
# 5  
Old 11-24-2015
And even IF the counter would be raised, upon first file (*_Processing) not found, its reset back to 1 - if it wouldnt break before that - leaving a untouched.
But since you work 10 times on the same file, that will not happen - and is therefor not required.

In fact, other than to do the very same task 10 times with the very same file, a is not used at all.

So my question: is that loop really required?

EDIT:
Code:
grep "$(date)" /pr/datastage/AUST/outputLargeFileForTesting_AUST.txt_Processing | wc -l  || echo "Either file dont exist or date not found."

hth
# 6  
Old 11-25-2015
Sorry about that I did add a space and not remove it after I wrote that, I meant to write add a space. And the script works.

I did also move the a=1 I saw that after I posted the script and didn't update the post, but thank you for pointing that out.

Thank you for your help. This script is now working as I wanted.

Thanks again for your help!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script called in loop from Bash Script

Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass). Here is... (0 Replies)
Discussion started by: cbo0485
0 Replies

2. Shell Programming and Scripting

Use loop in script

Hi All I want to make a script in which i can print prstat command output to a file in regular interval of 1 second I am using below script for the same dat=`date '+%d%m%y'` echo "###########################################################" >>prstat-$dat date >>prstat-$dat prstat 1 1... (3 Replies)
Discussion started by: devesh123
3 Replies

3. Shell Programming and Scripting

Loop Script?

Hello World I need to create a script to verify ports are open from a new jump off node to access over 200 different servers. I did a little research and put together this code: !/bin/sh exec 4<nodes.dat while read sys <& 4 do # PING TEST echo "$sys" ping $sys 1 # Example of... (1 Reply)
Discussion started by: paris123
1 Replies

4. Shell Programming and Scripting

Need help in loop script

Hi, This is script i am using currently for create SAN device creating. I need to do some change on this script #!/bin/ksh let x=0 let y=0 let count=$1 let size=$2 for dev in `cat /opt/emc/scripts/bin/noport-devs` do if ] then if then ... (8 Replies)
Discussion started by: ranjancom2000
8 Replies

5. Shell Programming and Scripting

How to loop use while loop in csh script?

Hi all, i got 2 text file. file.txt value.txt i want use C shell script to write out while both of the file got different limit....how i going to write it in 1 while loop? (4 Replies)
Discussion started by: proghack
4 Replies

6. Shell Programming and Scripting

a script with a for loop

Hi Gurus I have to write a script which does something like this /usr/local/gpg2/bin/GPG2 -o arch_696354351_1_23.dbf -d arch_696354351_1_23.dbf.gpg /usr/local/gpg2/bin/GPG2 -o arch_696354351_1_24.dbf -d arch_696354351_1_24.dbf.gpg /usr/local/gpg2/bin/GPG2 -o arch_696354351_1_25.dbf... (8 Replies)
Discussion started by: appsdba.nitin
8 Replies

7. Shell Programming and Scripting

While loop in a script

Hi, I have a unix shell script that I use to run the jobs, which internally calls a number of other jobs and outputs a log file. I want to call another shell script in the main script that constantly reads the log file that gets appended and emails the user upon each job completion. for... (5 Replies)
Discussion started by: rudoraj
5 Replies

8. Shell Programming and Scripting

loop in a script

I want to write a shell script which clones a file, example the name of the file to be cloned is "es" and I want its clone have the name "es1", "es2", "es3", and so on. Then another program called service needs the former clone as input, for example service up /home/es1, service up /home/es2... (4 Replies)
Discussion started by: Puntino
4 Replies

9. Shell Programming and Scripting

If then else loop in Shell script

Hi Following is the code . When I give input as Bangalore,its dospalying Welcome to Hitech City. But say , if I select Delhi or US, its not displaying the corresponding message. Its still says Welcome to Hitech City. Seems that it not entering in the elif part. Please suggest. #!... (4 Replies)
Discussion started by: pankajkrmishra
4 Replies

10. Shell Programming and Scripting

not quite sure how to loop this script!

:D can anyone tell me how to make this script continue after the *) I have been reading C and shell scripting and am confused.. I tried to impliment a while (1) and a continue after the *) but I keep getting end of file error..! also there a few different loops that I am not sure which type to... (3 Replies)
Discussion started by: moxxx68
3 Replies
Login or Register to Ask a Question