AIX how to read the file in function again and again


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers AIX how to read the file in function again and again
# 1  
Old 04-13-2014
AIX how to read the file in function again and again

dear friends

I have a wrote a shell script which works like this.
1.) a command is executed and the log is moved in the file.
2.) this file is copied in to the other file.
3.) used a grep command to find a particular word.
4.) if a particular word is there then the script will go to next step else it will sleep for 20 seconds.
5.) the source file which is now appended after sleep of 20 seconds will be copied the other file.
6.) the updated other file is read a particluar word is searched again.

the script is as shown below.

Code:
searchstring()
{
if [ `echo $req1 | grep -c "SUCCESS" ` -gt 0 ]
then
  echo "Sleep 10"
else
  echo "sleep 50"
  sleep 50
  cp dellog.txt dellog02.txt
  searchstring
fi
}
cp dellog.txt dellog02.txt
req1=`grep SUCCESS dellog02.txt`
#echo $req1
searchstring

now after executing this sheel script the copied file is showing the word that i want but it is executing else part and the same step is getting repeated.

i hope you people will help me.

---------- Post updated at 10:14 AM ---------- Previous update was at 09:49 AM ----------

dear friends

i got the answer. i missed line req1=`grep SUCCESS dellog02.txt` after copy in function.

thank you

ravi

Last edited by Scrutinizer; 04-13-2014 at 11:56 AM.. Reason: code tags
# 2  
Old 04-13-2014
Hmmmm, TAKE GREAT CARE!!!
You are calling searchstring() inside itself...
Sooner or later it could crash out...
Also not sure where your "sleep 10" sits, certainly not inside the function.
A while : or while true might be a better way using shell _builtins_.
# 3  
Old 04-16-2014
Dear wisecracker

Thank you for the reply. sleep 10 was just display something on the screen.
can you please help me by providing the code so that can call the function from outside unless my search gets the the wrd it wants.

Regards,

Ravi
# 4  
Old 04-16-2014
You marked this thread as [SOLVED] using the title colour change.

Here is a idea that is totally untested so be aware of that.

Do NOT discard your current incarnation until this is proven...
Code:
# Shebang line here...
# Loop something like this...
# <Some unknown setup code here>
# IMPORTANT:- UNABLE TO TEST.
#
cp dellog.txt dellog02.txt
# req1=`grep SUCCESS dellog02.txt`
req1=$(grep SUCCESS dellog02.txt)
#
while true
do
	# This section is added to exit the loop cleanly and manually...
	char=""
	# This line will sleep for 10 seconds UNLESS a key is pressed...
	read -n1 -s -t10 char
	# Q or q will exit/quit/breakout depending upon your requirement...
	if [ "$char" == "Q" ] || [ "$char" == "q" ]
	then
		break
		# exit # <some_return_code>
	fi
	# End of loop exit code...
	# if [ `echo $req1 | grep -c "SUCCESS" ` -gt 0 ]
	if [ $(echo $req1 | grep -c "SUCCESS") -gt 0 ]
	then
		# req1=`grep SUCCESS dellog02.txt`
		req1=$(grep SUCCESS dellog02.txt)
		echo "$req1"
		# sleep 10
	else
		echo "Copying file(s)..."
		cp dellog.txt dellog02.txt
		# sleep 50
		sleep 40
	fi
done
#
echo "You have exited the continuous loop..."


Last edited by wisecracker; 04-20-2014 at 03:43 PM.. Reason: Correct a typo in the if statement line...
# 5  
Old 04-20-2014
Thank you wisecracker it is working now i have made some changes to make it simple. Regards, Ravi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file input in while loop does not work on AIX system

I'm working on Aix 6.1 and using ksh shell. The below works fine on Linux bash or ksh shell . while IFS= read -r dirpath ; do echo "Hi" done <<<"$var" However, any such while loop that reads the input from file or variable using <<< fails on Aix system with the below error: Below... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

3. Homework & Coursework Questions

C++ Attempting to modify this function to read from a (;) semi-colon-separated file

After some thought. I am uncomfortable issuing my professors name where, there may be unintended side effects from any negative responses/feedback. Willing to re post if I can omit school / professor publicly, but can message moderator for validation? I am here for knowledge and understanding,... (1 Reply)
Discussion started by: briandanielz
1 Replies

4. AIX

Not able to read redo log file on AIX box

I have a oracle 10 G database installed on AIX6.1) server. The database user creates online redo log files with permissions 640 i.e. read access to group oinstall I am not able to read the files with another user part of the group oinstall. even tried to copy the files to another location,... (5 Replies)
Discussion started by: amitnm1106
5 Replies

5. Shell Programming and Scripting

Read Table,View,Package,Function and Procedure Name in a File

Hi I am new to Unix shell scripting. But i need help to slove the below issue. Issue description: I want to read table, view names and package names in a file my plan to find the table name is : search "From" key word find the table or view To find the packge name : Search "Package... (5 Replies)
Discussion started by: sboss
5 Replies

6. UNIX for Advanced & Expert Users

How UNIX/AIX handles a file deep down, say it's being read while another one tries to rename it?

Hi Thinkers, On AIX 5.3, we have a monitor program that reads the log file and searching for a certain string pattern that we define(say "transactionException"), if it sees it then it will raise an alert by sending an email. Because the log file XXX.log is rolling into XXX.log.0, XXX.log.1,... (2 Replies)
Discussion started by: TheGunMan
2 Replies

7. Shell Programming and Scripting

AIX file read for file name script

Hi al, Im trying to write something to read a date file and append each date to my file output name. Datefile: 20091001 20091015 Final output file I would like is: DATA_20091001_20091015.xls The script Im trying, but not working, is n=`wc -l < dates_yymmdd.txt` i=1 (2 Replies)
Discussion started by: NycUnxer
2 Replies

8. Programming

Cannot read a file with read(fd, buffer, buffersize) function

# include <stdio.h> # include <fcntl.h> # include <stdlib.h> # include <sys/stat.h> int main(int argc, char *argv) { int fRead, fPadded, padVal; int btRead; int BUFFSIZE = 512; char buff; if (argc != 4) { printf ("Please provide all of the... (3 Replies)
Discussion started by: naranja18she
3 Replies

9. Programming

read a file wich fscanf() in a function

I use fopen, fscanf, fclose to read a file. It can work well. since many files should be read, a function is created with the same code. But in the function, fscanf can not work well. for example, the first line of the the file is: > filename but the fscanf will give: 207/23/eee/34 it appears... (2 Replies)
Discussion started by: cdbug
2 Replies

10. UNIX for Dummies Questions & Answers

read function

Hello all In UNIX i wrote a program which simply establishes a conncetion with another system, using write system call i wrote a message to the server from client and from the server i send another message, for the second time i send a mesage using write system call to the server, when i send a... (1 Reply)
Discussion started by: rajashekaran
1 Replies
Login or Register to Ask a Question