Sponsored Content
Top Forums Shell Programming and Scripting Read input while another command is running && Post 302901787 by Kiah07 on Thursday 15th of May 2014 03:26:26 PM
Old 05-15-2014
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.

Code:
#/bin/bash
counter="1"
main() {
while {{ "$counter" <= "3" )) ; do
(timeout 10s tshark -l -i eth0 2>/dev/null > /tmp/scritp1 & ); keypress
list=$(</tmp/script1)
echo "$list"
counter=$((counter+1))
done
exit
}

keypress() {
echo "keypress"
read -t 10 -s -n 1 key &&
if [[ "$key" == "q" ]] ; then echo "quit"
exit
else main
fi
}
main

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to prompt for input & accept input in ONE line

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)
Discussion started by: newbie168
2 Replies

2. SuSE

inconsistent ls command display at the command prompt & running as a cron job

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)
Discussion started by: rajranibl
5 Replies

3. UNIX for Dummies Questions & Answers

sleep 10 && command doesn't work

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)
Discussion started by: chebarbudo
2 Replies

4. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

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)
Discussion started by: sowmya005
1 Replies

5. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

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)
Discussion started by: lowmaster
0 Replies

6. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

7. Shell Programming and Scripting

Using Grep & find & while read line in a script

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)
Discussion started by: Abv_mx81
0 Replies

8. Shell Programming and Scripting

[Solved] BASH - chaining TEST and COMMAND with && and II

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)
Discussion started by: jcdole
4 Replies

9. Shell Programming and Scripting

If && command giving wrong output

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)
Discussion started by: srkmish
4 Replies

10. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

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)
Discussion started by: weesiong
3 Replies
vga_waitevent(3)						Svgalib User Manual						  vga_waitevent(3)

NAME
vga_waitevent - wait for various I/O events SYNOPSIS
#include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <vga.h> int vga_waitevent(int which, fd_set *input, fd_set *output , fd_set *except, struct timeval *timeout) DESCRIPTION
This is the only function allowing you to wait for keyboard AND mouse events. It is based on the select(2) library function, so for deep understanding of vga_waitevent() look at select(2) as well. which can be 0 or logical ored together from VGA_MOUSEEVENT and VGA_KEYEVENT. If you are interested in waiting for file descriptors having input available or being ready for new write data or being in an exceptional condition (urgent data arrived on a TCP stream) set the corre- sponding bits in the fd_set structures passed (see select(3)). If you want vga_waitevent() to return after a timeout value pass a struct timeval with the desired value. If you are not interested in the corresponding events you may pass NULL for any of the pointers. If NULL is passed for timeout vga_waitevent() will not time out but block until any of the other events occurs. If the integer returned is < 0 an error occurred. Check the global variable errno for details. If a value >= 0 is returned it is a bitmask constructed using VGA_MOUSEEVENT and VGA_KEYEVENT to show which of these events occured. If any of these two occured the appropriate update functions are already called by vga_waitevent().vga_waitevent() operates in raw as well as non-raw keyboard mode. In the latter case use vga_getch(3) not vga_getkey(3) to read the newly arrived keys. Any of the file related conditions being met will be signalled by setting exactly the bits for files that met the conditions in the corre- sponding fd_set structures. If a non-NULL timeout is passed the remaining time is written into it on return. If it is 0 a timeout occured. (again: cf. select(2)) Therefore, depending on context, vga_waitkey(3) may return 0 if only special, non svgalib, events occured. EXAMPLES
If you want to wait blocking for a keypress OR a mouse event use: vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, NULL, NULL, NULL, NULL); If you want to wait for a keypress OR a mouse event but non-blocking use: #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <vga.h> struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0; vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, NULL, NULL, NULL, &timeout); You could do a similar thing by just calling mouse_update(); keyboard_update(); though. There is no such counterpart for the first example. Finally, there is a very nice eventtest(6) demo showing most capabilities of vga_waitevent(). BUGS
This function was introduced in 1.2.10. Unfortunately there was a typo in the first implementation which broke the case where input was NULL. Though fixed in 1.2.11 for optimal portability pass an empty fd_set instead of NULL as first argument. When not running in background mode, that is, the svgalib applcation is suspended while the VC is switched away, it seems vga_waitevent gets stuck and does no longer timeout. It is not clear if this is an svgalib bug, kernel bug or general problem. SEE ALSO
svgalib(7), vgagl(7), libvga.config(5), eventtest(6), mouse_getposition_6d(3), mouse_getx(3), mouse_update(3), mouse_waitforupdate(3), vga_getkey(3), vga_getch(3) AUTHOR
This manual page was edited by Michael Weller <eowmob@exp-math.uni-essen.de>. The exact source of the referenced function as well as of the original documentation is unknown. It is very likely that both are at least to some extent are due to Harm Hanemaayer <H.Hanemaayer@inter.nl.net>. Occasionally this might be wrong. I hereby asked to be excused by the original author and will happily accept any additions or corrections to this first version of the svgalib manual. Svgalib (>;= 1.2.11) 27 July 1997 vga_waitevent(3)
All times are GMT -4. The time now is 09:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy