Sponsored Content
Full Discussion: Exit to while read
Top Forums Shell Programming and Scripting Exit to while read Post 303007101 by lxdorney on Saturday 11th of November 2017 01:01:52 PM
Old 11-11-2017
hi Scott,
here my script

Code:
func_monitoring () {
tail -fn0 /tmp/test.log | \
while read line ; do
        echo "$line" | grep -q "pattern1"
        echo "$line" | grep -q "pattern2"
    if [ "$line" == "pattern1" ]
        then
                echo "patter1"
                break
    elif [ "$line" == "pattern2" ]
        then
                echo "patter2"
                break
    fi
done
}

func_menu () {

while :
  do
clear
  echo ""
  echo ""
  echo "               [1] Monitor the log"
  echo ""
  echo "               [2] Exit"
  echo ""
  echo ""
  echo "        Select Number"
  echo ""
  echo -n "        Please Select [1-2]: "
  read yourch
  case $yourch in
   1)  func_monitoring ; read -n 1;;
   2)  clear ; exit 0
       ;;
    *) echo "       Please select choice 1 or 2"
       read -n 1
       ;;
  esac
done
}
func_menu

---------- Post updated at 11:52 AM ---------- Previous update was at 11:51 AM ----------

after found any pattern must be go back to the menu after 5s but is not happening

---------- Post updated at 11:56 AM ---------- Previous update was at 11:52 AM ----------

here's the scripts goes:
screen 1
1. sh test.sh

Code:

               [1] Monitor the log

               [2] Exit


        Select Number

        Please Select [1-2]: 1

from screen 2
will execute this:
echo 'pattern1' >> /tmp/test.log

result
screen 1:

Code:

               [1] Monitor the log

               [2] Exit


        Select Number

        Please Select [1-2]: 1
patter1

is not go back to menu after echo the pattern, i need to go back to the main menu

---------- Post updated at 11:59 AM ---------- Previous update was at 11:56 AM ----------

---------- Post updated at 01:01 PM ---------- Previous update was at 11:59 AM ----------

Thanks scott,

Solved it by adding this:
Code:
		echo "        Please [Enter] key to continue..."
		ps aux |grep tail -m 1 |awk '{print "kill " $2}' |sh
                break


Last edited by lxdorney; 11-11-2017 at 01:59 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

2. Programming

exit(0) versus exit(1)

What is the difference between using exit(0) and exit(1) to exit a program? Which should I use? (9 Replies)
Discussion started by: enuenu
9 Replies

3. UNIX for Dummies Questions & Answers

what is meaning of exit(0) and exit(1)

can u tell me what is the meaning of exit(0),exit(1),exit(2) what is diff amonng these. Amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

4. Shell Programming and Scripting

urgent -read exit status

i have written a shell script that invokes main class of a java prg. the java prg does a System.exit(0) or (1) based on condition. how can i read or check the status in unix.... (4 Replies)
Discussion started by: iamcool
4 Replies

5. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

6. UNIX for Advanced & Expert Users

Returning exit code from a while read $inputline

Hi searched hi and wide for this with no luck. Maintaining a bash script that #!/usr/bin/bash #does some stuff like setting env etc. f_do_dbwork ... .. #Now I want to exit with the value of $err however $err is re-initialised to 0 on exiting the function Always 0 .... ... (3 Replies)
Discussion started by: StevePr
3 Replies

7. UNIX for Advanced & Expert Users

Timing READ command - any key to exit

Hello everyone, I would like some help on an issue I have related to the read command with ksh93 (Unix AIX). I want to implement a 'press any key to exit' scenario. I have the following code: STTY=$(stty -g) if ;then stty -echo -icanon time 0 min 0 fi k="" while ];do read k #... (5 Replies)
Discussion started by: gio001
5 Replies

8. Shell Programming and Scripting

Need the difference between exit 1 & exit 7

Hi In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Discussion started by: ginrkf
3 Replies

9. Shell Programming and Scripting

Read exit value from Shell script

Hi all, I have a situation to read exit value of a command (not exit code) and process further. bash-4.2$ returnvalue=`ssh DOMAIN\\\\user1@10.7.7.68 'cmd /c "del C:\Users\user1\db_test.bak"'` Could Not Find C:\Users\user1\db_test.bak bash-4.2$ echo $? 0 bash-4.2$ echo $returnvalue... (3 Replies)
Discussion started by: baluchen
3 Replies

10. UNIX for Beginners Questions & Answers

UNIX Pipe -Exit when there are no bytes to read

Hi All, I'm creating a program which reads millions of bytes from the PIPE and do some processing. As the data is more, the idea is to read the pipe parallely. Sun Solaris 8 See the code below: #!/bin/sh MAXTHREAD=30 awk '{print $1}' metadata.csv > nvpipe & while do ... (3 Replies)
Discussion started by: mr_manii
3 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy