Skip to main content
Tweeted twitter.com/#!/StackUnix/status/565662787675103232
edited tags
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

bash script "tail -f logfile" On Ctrl+C, kill the current command but continue execution on ctrl+cexecuting the script

basically, I have a bash script, wherein I execute a line, sleep for sometime and then tail -ftail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -ftail -f and then move to the next line till the bash script finishes execution:

Here is what I have done thus far:

#!/bin/bash # capture the hostname host_name=`hostname -f` # method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c' echo "===================================================" echo "On $host_name: running some command" some command here echo "On $host_name: sleeping for 5s" sleep 5 # Look for: "pattern" in log_file.log # trap 'continue' SIGINT trap 'continue' SIGINT echo "On $host_name: post update looking for pattern" tail -f /var/log/hadoop/datanode.log | egrep -i -e "receiving.*src.*dest.*" # some more sanity check echo "On $host_name: checking uptime on process, tasktracker and hbase-regionserver processes...." sudo supervisorctl status process # in the end, enable the balancer # echo balance_switch true | hbase shell 

The script works but I get the error, what needs to change/ what am I doing wrong?

./script.sh: line 1: continue: only meaningful in a `for', `while', or `until' loop 

Thank you for the pointers/help

bash script "tail -f logfile" continue execution on ctrl+c

basically, I have a bash script, wherein I execute a line, sleep for sometime and then tail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -f and then move to the next line till the bash script finishes execution:

Here is what I have done thus far:

#!/bin/bash # capture the hostname host_name=`hostname -f` # method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c' echo "===================================================" echo "On $host_name: running some command" some command here echo "On $host_name: sleeping for 5s" sleep 5 # Look for: "pattern" in log_file.log # trap 'continue' SIGINT trap 'continue' SIGINT echo "On $host_name: post update looking for pattern" tail -f /var/log/hadoop/datanode.log | egrep -i -e "receiving.*src.*dest.*" # some more sanity check echo "On $host_name: checking uptime on process, tasktracker and hbase-regionserver processes...." sudo supervisorctl status process # in the end, enable the balancer # echo balance_switch true | hbase shell 

The script works but I get the error, what needs to change/ what am I doing wrong?

./script.sh: line 1: continue: only meaningful in a `for', `while', or `until' loop 

Thank you for the pointers/help

On Ctrl+C, kill the current command but continue executing the script

I have a bash script, wherein I execute a line, sleep for sometime and then tail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -f and then move to the next line till the bash script finishes execution:

Here is what I have done thus far:

#!/bin/bash # capture the hostname host_name=`hostname -f` # method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c' echo "===================================================" echo "On $host_name: running some command" some command here echo "On $host_name: sleeping for 5s" sleep 5 # Look for: "pattern" in log_file.log # trap 'continue' SIGINT trap 'continue' SIGINT echo "On $host_name: post update looking for pattern" tail -f /var/log/hadoop/datanode.log | egrep -i -e "receiving.*src.*dest.*" # some more sanity check echo "On $host_name: checking uptime on process, tasktracker and hbase-regionserver processes...." sudo supervisorctl status process # in the end, enable the balancer # echo balance_switch true | hbase shell 

The script works but I get the error, what needs to change/ what am I doing wrong?

./script.sh: line 1: continue: only meaningful in a `for', `while', or `until' loop 
Source Link
cog_n1t1v3
  • 143
  • 1
  • 1
  • 5

bash script "tail -f logfile" continue execution on ctrl+c

basically, I have a bash script, wherein I execute a line, sleep for sometime and then tail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -f and then move to the next line till the bash script finishes execution:

Here is what I have done thus far:

#!/bin/bash # capture the hostname host_name=`hostname -f` # method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c' echo "===================================================" echo "On $host_name: running some command" some command here echo "On $host_name: sleeping for 5s" sleep 5 # Look for: "pattern" in log_file.log # trap 'continue' SIGINT trap 'continue' SIGINT echo "On $host_name: post update looking for pattern" tail -f /var/log/hadoop/datanode.log | egrep -i -e "receiving.*src.*dest.*" # some more sanity check echo "On $host_name: checking uptime on process, tasktracker and hbase-regionserver processes...." sudo supervisorctl status process # in the end, enable the balancer # echo balance_switch true | hbase shell 

The script works but I get the error, what needs to change/ what am I doing wrong?

./script.sh: line 1: continue: only meaningful in a `for', `while', or `until' loop 

Thank you for the pointers/help