This is a discussion on Scripting Help within the Sun Solaris Administration forums, part of the Solaris Operating System category; --> I wrote something like this a long time ago but forgot what I did. I have a application that ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I wrote something like this a long time ago but forgot what I did. I have a application that generates a bunch of console output during startup and then finally prints out a message like "Server started." when done. I want a startup script that will go into a while loop and grep for the "Server started" string. One is sees that, echos a message to the screen and exits. I am also running this command from a nohup so the script will actually need to monitor nohup.out for the startup string. I have the entire script written with the exception of the while loop. Can anyone help me out? My bash is a bit rusty. Thx -CC |
| |||
| In article <3F0DEAE2.5030705@echeeba.com>, Big Chuck <ccarson@echeeba.com> wrote: > >I wrote something like this a long time ago but forgot what I did. > >I have a application that generates a bunch of console output during >startup and then finally prints out a message like "Server started." >when done. > >I want a startup script that will go into a while loop and grep for the >"Server started" string. One is sees that, echos a message to the screen >and exits. I am also running this command from a nohup so the script >will actually need to monitor nohup.out for the startup string. > >I have the entire script written with the exception of the while loop. > >Can anyone help me out? My bash is a bit rusty. while read line do if [[ $line = "Server started." ]] then echo "It's started!" break fi done < nohup.out -- Barry Margolin, barry.margolin@level3.com Level(3), Woburn, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group. |
| ||||
| Barry Margolin wrote: > > In article <3F0DEAE2.5030705@echeeba.com>, > Big Chuck <ccarson@echeeba.com> wrote: > > > >I want a startup script that will go into a while loop and grep for the > >"Server started" string. One is sees that, echos a message to the screen > >and exits. I am also running this command from a nohup so the script > >will actually need to monitor nohup.out for the startup string. > > > >I have the entire script written with the exception of the while loop. > > > >Can anyone help me out? My bash is a bit rusty. > > while read line > do > if [[ $line = "Server started." ]] > then echo "It's started!" > break > fi > done < nohup.out If the "nohup.out" file is being added to while the script is run, as the OP would seem to indicate, that will not work, as it will terminate when it comes to the end of nohup.out as it then exists. It should be something like: tail +1f nohup.out | while read line do echo $line | egrep -s "Server started" && break done echo "It's started" if "Server started" is only part of the message, or tail +1f nohup.out | while read line do [[ "$line" = "Server started" ]] && break done echo "It's started" if the line is guaranteed to contain only "Server started", so that it tracks nohup.out while is is being created. John Howells |