This script runs tshark, then displays the output. I want to read a keypress at all times throughout this script, especially during the 10 seconds that tshark is running. This code however, only takes input before tshark runs.
If that's the entire script and you just want to run "tshark" for 10 seconds, then wait 5 seconds and do it again. Then if you can accept typing "^c" instead of "q" to stop it, the whole thing can probably be reduced to this:
You may have to hit "^c" twice to stop the script sometimes.
If you want to keep the current logic, where you hit "q" to stop and that also stops the "tshark", then you need to do something more sophisticated.
You'll have to run "tshark" as a background process, capture the PID in the shell script, then if "q" is entered kill that PID before exiting.
The other problem you'll have is that the while loop will cycle every 5 seconds (since you're using "-t 5" on the read), but the "tshark" subprocess will run for 10 seconds. So you'll wind up with an ever increasing number of "tshark" processes running in parallel.
If you make the timeout on the "read" longer than the timeout on the "tshark" calls that won't be a problem, but it will also mean the pause between "tshark" runs will be longer than 5 seconds.
If you want to fix THAT problem, then you need to add logic to the shell script to make sure that you only have one "tshark" running at once.
So what to do depends on how big of a hole you want to dig for yourself.
Hey guys, no it's not the entire script and I needed many other keys. This was just the quickest and easiest way to show the problem area. I solved it by running tshark in the background, and had to output data to /tmp since I couldn't export the variable from the subshell back to the main process. As for the time gap I used 10 seconds on both read -t and timeout. I figure since the (timeout tshark) gets called and backgrounded right before keypress is called, it should work out pretty good.
Hi All,
Do you have any sample script,
- auto get file from SFTP remote server and delete file in remove server after downloaded.
- only download specify filename
- auto upload file from local to SFTP remote server and delete local folder file after uploaded
- only upload specify filename
... (3 Replies)
Hi All,
I am trying to run a script which will search for 2 strings(stopped,started) in a text file and echo an output depending on below condition
-bash-3.2$ cat trial1.txt
v
ggg
f
-bash-3.2$ cat trial1.sh
VAR9=` grep 'stopped' /tmp/trial1.txt`
VAR10=` grep 'started'... (4 Replies)
Can you explain what this line of script is doing.
What I have understood is :
-- variable C is the name of a software which is either not installed, so it must be installed or allready installed and then should be update if newer version found
-- branch B="$B $C" is to install the software
--... (4 Replies)
Hello people!
I would like to create one script following this stage
I have one directory with 100 files
File001
File002
...
File100
(This is the format of content of the 100 files)
2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0
then I have one... (0 Replies)
Hi, I have text file abc.txt. In this file, I have the following data.
Input:
Mr Smith & Mrs Smith
Mr Smith &apos Mrs Smith
Mr Smith & Mrs Smith
Mr Smith& Mrs Smith
Mr Smith &Mrs Smith
Output:
Mr Smith & Mrs Smith
Mr Smith &apos Mrs Smith
Mr Smith & Mrs Smith
Mr Smith&... (4 Replies)
Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.
I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Hi friends,
I have a script that sets the env variable path based on different conditions.
Now the new path variable setting should not done in the same terminal or same shell.
Only a new terminal or new shell should have the new path env variable set.
I am able to do this only as follows:
>cd... (1 Reply)
Hi there,
I found a trick to easily postpone a command by a few seconds:
supernova:~# sleep 10 && command &If you logout, the command should still be executed... But not all the time.
Could anyone of you explain me why the following command is executed even after logging out:
supernova:~# sleep... (2 Replies)
Sir,
I using the following commands in a file (part of a bigger script):
#!/bin/bash
cd /opt/oracle/bin
ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out
If I run this from the command prompt the result is:
2007-05-16
if I run it as a cron job then... (5 Replies)
hi,
am a new learner to shell programming.
i have a script which will prompt for user to key in their name & display their name afterwards.
script
=====
echo "Pls enter your name:"
read name
echo "Your name is $name."
output
=====
Pls enter your name:
Bob
Your name is Bob.
what... (2 Replies)