How to stop the tail -f command executed in a subclass

I tried various steps from http://mywiki.wooledge.org/ProcessManagement and http://mywiki.wooledge.org/BashFAQ/068My , but I can not achieve how to kill the tail -f command after a certain time interval.

my script:

#!/bin/bash

function strt ()
{
command 1..
command 2..
}

export -f strt
su user -c 'set -e && RUN_Server.sh > server.log && tail -f server.log & pid=$! { sleep 20; kill $pid; } && strt'

exit 0.

I am trying to kill the tail pid -f server.log and go to 'strt', which is a small function, to find if the jboss server is running or not.

on execution i get an error like

bash: -c: line 0: syntax error near unexpected token `{'.

+3
source share
4 answers

try it

timeout 20 tail -f server.log
+3
source
pid=$! { sleep 20 ; kill $pid; }

? , { ?

0

, , , slee p , tail.

:

command1 && command2

, command1 0, command2. :

if command1
then
     command2
fi

. Weblogic, , , - .

named pipes (Directions) . , Weblogic . , , .

.

0

- , pid , (&), / :

$ tail -f /var/log/syslog & ; echo $! 
bash: syntax error near unexpected token `;'

... , .

, , , & () / bash - , ; ( )! :

BashSheet - Greg Wiki

  • []; [] [ ]
    .
  • [] []
    .

, , &, bash, ;, - bash chokes. , ;, & :

$ tail -f /var/log/syslog & echo $! 
[1] 15562
15562
$ May  1 05:39:16 mypc avahi-autoipd(eth0)[23315]: Got SIGTERM, quitting.
May  1 06:09:01 mypc CRON[2496]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete)
May  1 06:17:01 mypc CRON[5077]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  1 06:25:01 mypc CRON[7587]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
^C
$ May  1 06:52:01 mypc CRON[15934]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ))
$ ps -p 15562
  PID TTY          TIME CMD
15562 pts/0    00:00:00 tail
$ kill 15562
$ ps -p 15562
  PID TTY          TIME CMD
[1]+  Terminated              tail -f /var/log/syslog
$ ps -p 15562
  PID TTY          TIME CMD
$ 

... .

OP, :

$ tail -f /var/log/syslog & pid=$! { sleep 2; kill $pid; } 
bash: syntax error near unexpected token `}'

- bash & , "" pid=$!, - "" , , {, . , , pid=$! ;, :

$ tail -f /var/log/syslog & pid=$! ; { sleep 2; kill $pid; } 
[1] 20228
May  1 05:39:16 mypc avahi-autoipd(eth0)[23315]: Got SIGTERM, quitting.
May  1 06:09:01 mypc CRON[2496]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete)
May  1 06:17:01 mypc CRON[5077]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  1 06:25:01 mypc CRON[7587]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
May  1 06:52:01 mypc CRON[15934]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ))
$ ps -p 20228
  PID TTY          TIME CMD
[1]+  Terminated              tail -f /var/log/syslog
$ 

, tail -f, , , bash ( 4.2.8 (1)) Enter , "[1]+ Terminated ...".

, ,
!

0

All Articles