LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-01-2009, 11:52 AM   #1
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Rep: Reputation: 41
Shell script-How to call tail then exit when 'END timestamp' appears in log?


I need to write a script that will log in to a remote server, launch a process, and then display the log output from that process and finally end the ssh session and exit the script when the process ends.

My idea for how to do this task is something like this, but I have no idea how to make it end.

Code:
#! /bin/sh
#
echo "starting at `date`"
ssh user1@remote_server nohup /opt/program/bin/program.pl -p parameter1 -q parameter2 --long_parameter3 &

ssh user2@remote_server tail -f /var/log/program/the_log.log

# when the following line appears in the log, I need to to exit this script
#END       2009.05.01 02:40:45
#where the timestamp is any valid date-time in this format.

echo "finished at `date`"
exit 0
The process "program.pl" will be finished at the point where "END" appears in the log, so maybe I could monitor that instead. But I'm not sure how to do that either.
 
Old 05-01-2009, 01:52 PM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
One clue might be to use --pid=$$ with tail, which causes tail to exit when pid dies. $$ is the pid of the script. Maybe pipe the tail -f to grep: | grep END && exit?
 
Old 05-01-2009, 02:08 PM   #3
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Thanks. Both suggestions sound like great ideas.
I would like to use --pid with tail, but the process just shows up as "perl" which is pretty generic.

Here's what I see from top:

Code:
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
 5118 root      20   0  195m 155m 2300 R   69  1.9   2:50.70 perl
This gives the correct result, but what if other perl scripts are running? Is there a way to pin this down to the specific perl script I'm running?
Code:
$ pgrep perl
5118
Looking at the other option (pipe the tail -f to grep), is there a way that I can still see the output from tail and also use this method?

Thanks
 
Old 05-01-2009, 02:19 PM   #4
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
try using tee. It will allow you to send output to stdout and to files. You should be able to use some kind of redirection to send output to a pipe and to stdout.
 
Old 05-01-2009, 02:29 PM   #5
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
thanks. It is good to know about tee. But I'm having trouble conceptualizing how to put all this together...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 03:07 AM
Exit from tail -f, and not kill underlying script? fur Programming 4 03-28-2008 11:52 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
call another script and have the inital script exit mjtice Programming 1 09-11-2005 11:54 AM
running root-tail from shell script not working Nuk Linux - Newbie 1 04-09-2004 08:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration