stopping tail function after ctrl + c


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting stopping tail function after ctrl + c
# 1  
Old 12-27-2011
stopping tail function after ctrl + c

say i have a statement like this in a script
Code:
 
 
tail -f /opt/blah/blha/user.log > final.log
if [ $? -eq 130 ] ;then
cat final.log | grep -i "servicer_user" > service.log
cat final.log | grep -i "logic_user" > logic.log
fi
echo "script completed"

but when the script is running if i press ctrl + c the sctipt stops however no other statements after tail statement are executed... how to rectify this... 130 is the exit status for cntrl + c.. but i tried this even then its not working... Smilie
# 2  
Old 12-27-2011
what is it that you are trying to achieve?...
If you want to get specific no of lines using tail, use tail -100 user.log...

--ahamed

---------- Post updated at 02:27 AM ---------- Previous update was at 02:23 AM ----------

Try this...
Code:
#!/bin/bash

trap 'echo' INT

tail -f /tmp/somelog

echo $?
echo "1"
echo "2"
echo "3"

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-27-2011
what i want is when i run the script it will start to tail the file user.log and paste it in another file.... then when i press ctrl+c(which is the only way to stop the tail) the script will then search for keywords in that created file and paste it into another file....
# 4  
Old 12-27-2011
You can try the code in the previous post!

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 12-27-2011
thanks your code worked.. :-) :-) :-) :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

2. UNIX for Dummies Questions & Answers

Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends, I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script. #! /bin/sh echo "select * from tab; commit;" > data.sql I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit... (1 Reply)
Discussion started by: royalibrahim
1 Replies

3. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

4. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

5. Shell Programming and Scripting

Help with getting a Ctrl-C trap working w/ a piped tail -f...

Hi All, Although each line below seems to work by itself, I've been having trouble getting the Control-C trap working when I add the "|perl -pe..." to the end of the tail -f line, below. (That |perl -pe statement basically just adds color to highlight the word "ERROR" while tailing a log... (2 Replies)
Discussion started by: chatguy
2 Replies

6. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

7. Shell Programming and Scripting

Stopping tail -f when certain string found?

Hi, I need to monitor a log file for a certain string ("Phase 2 ended") which indicates that the job which creates the log file has finished loading its data file. Once the string "Phase 2 ended" is found in the log file I would then like to stop checking that log and check to see if another... (3 Replies)
Discussion started by: jake657
3 Replies

8. Shell Programming and Scripting

Catching ctrl-C or ctrl-D

Hi there, I'm using HP-UX 11 machine. I am running a script, thats gonna take a long time to execute. When I press ctrl-c to come out of my script, I have to catch that signal(ctrl-c) and display that ctrl-c had been pressed. How can I do it. Thanks in advance (2 Replies)
Discussion started by: sendhilmani123
2 Replies

9. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies
Login or Register to Ask a Question