Sponsored Content
Top Forums Shell Programming and Scripting How to get input from keyboard with watch? Post 302940167 by bacarrdy on Wednesday 1st of April 2015 08:11:38 PM
Old 04-01-2015
How to get input from keyboard with watch?

Hello,

i`m trying to create an network monitoring script and i dont know how to make affect that script by pressing an key from keyboard and that script runs not in while or for or any other loop, but with bash command watch

for example: i have created an file (for example check) with content

Code:
watch --no-title ./check1

and file check1 is:

Code:
#!/bin/bash

#total packets
nfdump ... > packets
#syn packets
nfdump ... > syn
#fyn packets
nfdump ... > fyn
#udp packets
nfdump ... > udp
#tcp packets
nfdump ... > tcp
#icmp packets
nfdump ... > icmp
#mail
nfdump ... > mail
#ssh
nfdump ... > ssh
#bytes
nfdump ... > bps

if [ -z "$1" ] || [ "$1" == 1 ] ; then
printf '%-15s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s\n' ip pckt1 tcp2 udp3 syn4 fyn5 icmp6 mail7 ssh8 > test1
for i in $(cat packets | awk {'print $2'})
do
pck=`cat packets | grep -E "\s$i\s" | awk {'print $3'}`
tcp=`cat tcp | grep -E "\s$i\s" | awk {'print $3'}`
udp=`cat udp | grep -E "\s$i\s" | awk {'print $3'}`
syn=`cat syn | grep -E "\s$i\s" | awk {'print $3'}`
fyn=`cat fyn | grep -E "\s$i\s" | awk {'print $3'}`
icmp=`cat icmp | grep -E "\s$i\s" | awk {'print $3'}`
mail=`cat mail | grep -E "\s$i\s" | awk {'print $3'}`
ssh=`cat ssh | grep -E "\s$i\s" | awk {'print $3'}`
if [ -z "$tcp" ];
then
tcp=0
fi
if [ -z "$udp" ];
then
udp=0
fi
if [ -z "$syn" ];
then
syn=0
fi
if [ -z "$fyn" ];
then
fyn=0
fi
if [ -z "$icmp" ];
then
icmp=0
fi
if [ -z "$mail" ];
then
mail=0
fi
if [ -z "$ssh" ];
then
ssh=0
fi

printf '%-15s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s\n' $i $pck $tcp $udp $syn $fyn $icmp $mail $ssh >> test1
done
cat test1

else
echo "usage explanation"
echo "" > test1
fi
sleep 2

script works fine, but i want if user press 1 or 2 or 3 ... to sort some columns so i must to get pressed key

i have tryed:

Code:
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
keypress=''
keypress="`cat -v`"

with while loop works fine, but with watch it wont work and i want to use watch because it nicely print content by opened putty window size

or if its hard to do then maybe its possible to print content by opened putty window size?

Last edited by bacarrdy; 04-01-2015 at 09:26 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

suppressing keyboard input

Setup Info: This User Id and Password mention below are being used with the ISQL command to connect to a sybase database so they are likely to not be the same as those that were signed on from the session. Situation: Using a korn shell, the shell prompts for a User Id and Password. During the... (1 Reply)
Discussion started by: anthreedhr
1 Replies

2. Shell Programming and Scripting

Don't show keyboard input on terminal

I am developing a script that will run with '/bin/ksh' shell. The script is intended to receive a password by keyboard input, but for security reasons I would like to hide what the user is typing. The keyboard input is being caught by 'read' command. exmaple : echo "Please type your new... (1 Reply)
Discussion started by: marianor31
1 Replies

3. Programming

Detecting Keyboard Input without return

Hi, I need a way to detect the up and down arrow key inputs for my program. I do not want to wait for the return key to be entered(so that rules out getch() and family). Also I need to process several of these inputs in parallel, by servicing each request with a thread. Is that possible? ... (4 Replies)
Discussion started by: ravneetd
4 Replies

4. Programming

Keyboard Input

Does anyone know how do you determine the user idle time of STDIN in order to log the user out for being idle too long. I would like to write a c program to do this but I it is not clear upon how to determine idle time from keyboard input. I have found that the "who.c" source file uses the last... (4 Replies)
Discussion started by: cpaquette
4 Replies

5. UNIX for Advanced & Expert Users

[Debian] Stop input from keyboard and mouse

Dear friends, I need to stop getting input from keyboard and mouse at some specific time like, every day from 6 PM to 7PM likewise. How can I do this. Kindly guide me to do this. I need to block the input. I am using Debian OS. (5 Replies)
Discussion started by: nagalenoj
5 Replies

6. UNIX for Dummies Questions & Answers

Testing for correct user input from keyboard

What script can I use to catch errors in a shell script if user inputs alpha numeric characters instead on integers from the keyboard? (0 Replies)
Discussion started by: Pauline mugisha
0 Replies

7. Shell Programming and Scripting

Keyboard input question

How would I change up a script that currently has something like: bash script echo what's 1 2 3 4? then using read 1 2 3 4 I type 1 2 3 4. so in the script i can do stuff like echo $1 $2 $3 $4 and such... i was just doing echo "1 2 3 4"|bash script But was wondering how could I... (5 Replies)
Discussion started by: biopulse
5 Replies

8. Shell Programming and Scripting

sed execution with input from keyboard

> sed '' Hello hi Hello output How hi output ^D How > sed should take each line as input, process and output the result. In the above scenario the input is passed from keyboard and the output of 'Hello' as you can see is displayed on the screen after 'hi' is passed as input but not as... (1 Reply)
Discussion started by: loggedin.ksh
1 Replies

9. Shell Programming and Scripting

Input keyboard keys upon program launch

Hey guys, first post! I want to write a script that will wait 1 second and then input the keys CTRL+ALT+J to the application i just opened. The program is dosbox, and thay key combination starts video recording :) I have no idea how to program this, can anyone help please? thanks in advance! (2 Replies)
Discussion started by: brunobliss
2 Replies

10. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies
nstreams(1)							   Users Manuals						       nstreams(1)

NAME
network streams - a tcpdump output analyzer SYNOPSIS
nstreams [ -v ] [ -c nstreams-services ] [ -n nstreams-networks_file ] [ -N [ -i ] [ -I ]] [ -r ] [ -O output [ -D iface ] [ -Y ]] [ -u ] [ -U ] [ -B ] [ -f tcpdump_file ] [ -l <iface> ] [ tcpdump output ] DESCRIPTION
nstreams is a utility designed to identify the IP streams that are occuring on a network from a non-user friendly tcpdump output of several megabytes. This is especially useful when you plan to install a firewall but if you do not know the nstreams that the network users are generating (http, real audio, and more...). nstreams can read the tcpdump output directly from stdin, or from a file. It can even generate the con- figuration file of your firewall, using the -O option. OPTIONS
-c <nstreams-services-file> The path to an alternate nstreams service file. This file is used to identify each protocol. See the services file section later in this manual page. -n <nstreams-networks-file> The path to an alternate nstreams network file. This file is used to identify which hosts belong to which network. See the networks file section later in this manual page. -f <tcpdump output file> The path to the file to read data from. This file must have been generated using 'tcpdump -w filename'. -l <iface> Listen directly on interface <iface>. This avoids the use of tcpdump. -N print the networks names instead of the hosts IP addresses. The intra-network traffic will not be shown. Use this option twice to show the networks IP address instead of their names. -i Also show the intra-network traffic (must be used with -N) -I Only show the intra-network traffic (must be used with -N) -r be redundant. That is, the same streams will be printed each time they appear in the dump. -v print version number and exit. -O <type> output type. You can use this option to generate your firewall startup script. Do nstreams -h to see the supported output types. -D <iface> interface to apply to output onto. Must be used with -O. -Y The firewall rules that will be generated will deny all packets coming from the outside trying to establish connections to the inside. If you system is not serving anything, then it's safe to turn on this option. -u Do not print the unknown streams -U Only print the unknown streams -B Show broadcasts and networks USAGE
Let tcpdump(1) run some time on your network (like one week), and save its output in a file, by doing : tcpdump -l -n > output or tcpdump -w filename Then, feed nstreams with this output file, and it will turn it into a easily-readable file which will help you to write efficient firewall filters. You may also do : tcpdump -l -n | nstreams or nstreams -f filename (if you used tcpdump -w) THE SERVICES FILE
The service file contains the description of each protocol, as well as their name. Its syntax is : protocol_name:server_port(s)/{udp,tcp}:client_ports(s) or : protocol_name:type(s)/icmp:code(s) Whereas : protocol_name is the name of the protocol described. This name may contain any character, including space, except ':'. server_port(s) is the range of ports used by the server. Usually, you will want to define one server port only, but you may enter any range you want. ip_protocol is the IP protocol that this protocol is lying onto. Acceptable values are tcp and udp client_port(s) is the range of ports that the client may use. You can set this to any or, for more accurate results, to ports ranges, like '1-1024,2048-4096'. The rules are : 'first match, first taken'. SERVICE FILE EXAMPLE
Using this syntax, you would declare the ssh protocol by : ssh-unix:22/tcp:1000-1023 Because the Unix version of the ssh client uses a privileged port to connect onto the ssh server which listens on port 22. THE NETWORKS FILE
The networks file is used to define sets and subsets of hosts (also known as networks). This avoids redundancy in the output file. The syn- tax format for this file is : network name:ip/mask Whereas the network name is whatever you want, the IP is the ip of the network, and the mask is the CIDR netmask of the network. The rule is 'first match, first taken'. NETWORKS FILE EXAMPLE
admin:192.168.19.0/29 whole_subnet:192.168.0.0/16 internet:0.0.0.0/0 LIMITS
o nstreams can only parse the output of 'tcpdump -n' o Even though the output of nstreams is easier to read than the one of tcpdump, it is still not easily readable. Use sort(1) on the nstream output to get a more readable file. o This program could have been written in perl FILES
/etc/nstreams-services /etc/nstreams-networks SEE ALSO
tcpdump(1) AUTHORS
Concept : Herve Schauer Consultants - http://www.hsc.fr Coding : Renaud Deraison <deraison@cvs.nessus.org> BUG REPORTS
Please send all your bug reports with the detail of your configuration to Renaud Deraison <deraison@cvs.nessus.org> nstreams July 1999 nstreams(1)
All times are GMT -4. The time now is 01:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy