Creating an Interactive Bash Script to Analyze a PCAP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating an Interactive Bash Script to Analyze a PCAP
# 1  
Old 04-17-2013
Creating an Interactive Bash Script to Analyze a PCAP

Hello Everyone,

I am currently trying to write a Bash Script to call a PCAP file. The command I will use in the script will be the following:

tshark -r test.pcap -T fields -e frame.number -e frame.time -e eth.src -e eth.dst -e ip.src -e ip.dst -r ip.proto -E header=y -E separator=, quote=d -E occurance=f > pcap.csv

This command will allow me to see everything I need in a nicely formatted CSV file however I am struggling to write an interactive script to input both the name of the pcap (testfile.pcap above) and the name of the csv file (testfile.csv above) for the output to be saved to.

Does anyone know how I could put this into an interactive script so that when an admin runs the script, they can input the name of the existing pcap and the name of the csv file that the formatted information should be saved to?

So far my script contains the following:
#!/bin/bash

echo="What is the name of your PCAP input file?"

echo="What is the name of your CSV output file?

tshark -r test.pcap -T fields -e frame.number -e frame.time -e eth.src -e eth.dst -e ip.src -e ip.dst -r ip.proto -E header=y -E separator=, quote=d -E occurance=f > pcap.csv

I have been watching and reading a lot about bash scripting and I think the test.pcap and pcap.csv above should each be a variable but how do I make a variable represent something input by a user? Essentially I would like the user to be able to enter in the name of the pcap (and location if need be) to analyze, followed by the name of the csv file to send the output to.

Thanks in advance!

Tuxor
# 2  
Old 04-17-2013
Code:
#!/bin/bash

echo -n "What is the name of your PCAP input file? "
read in_pcap

echo -n "What is the name of your CSV output file? "
read out_csv

tshark -r "$in_pcap" -T fields -e frame.number -e frame.time \
-e eth.src -e eth.dst -e ip.src -e ip.dst -r ip.proto -E header=y -E separator=, quote=d -E occurance=f > "$out_csv"

This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-17-2013
When the user specifies the in_pcap (the pcap that already exists), will they have to specify the path of the pcap so that the script knows what pcap to run the script on?
# 4  
Old 04-17-2013
If it's in the current directory, they don't need to give the path. If it's not, they do need to give the path.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-17-2013
Thank both of you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a condition on a bash script

I wrote a code to find codons in a DNA string. The only problem I have is how do I make the code only work for a file with DNA. This means the file only has the characters a,c,g,t and no white space characters. (3 Replies)
Discussion started by: germany1517
3 Replies

2. Shell Programming and Scripting

Bash interactive Script Required

Dear All, Please help in creating a bash script to fetch records from multiple files the script should ask inputs of file type and column level input(at least 4 col of each file type) I have 4 sort of Files, A,B,C,D. file names are like A_0112.unl, A_01215.unl, A_0001.unl and same with B C... (3 Replies)
Discussion started by: Muhammad Ali
3 Replies

3. Shell Programming and Scripting

Passing arguments to interactive program through bash script, here document

Dear Users, I have installed a standalone program to do multiple sequence alignment which takes user parameters to run the program. I have multiple sequence files and want to automate this process through a bash script. I have tried to write a small bash code but its throwing errors. Kindly... (13 Replies)
Discussion started by: biochemist
13 Replies

4. Shell Programming and Scripting

Creating an Interactive Variable

Goal: I want run a Bash script that runs some conditional if statements on a specific file path that a user defines. Question: How do I build the prompt so the script asks the user to define the file path and then use that input as a variable? I'm guessing I will use a read builtin but I'm... (3 Replies)
Discussion started by: sudo
3 Replies

5. Shell Programming and Scripting

Non interactive su in bash script

Hi, I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt? Thank you. (4 Replies)
Discussion started by: hce
4 Replies

6. Shell Programming and Scripting

Script in bash wchich creating a new users...

Hi, I am a new on this forum but i like :) I need a script in bash which will be crating a new user with folder for websites. For example: I will run this program and he creating a new user(with my name) and folder whcich name like user and if i will localho/~user in browser, she show me files from... (1 Reply)
Discussion started by: puclavv
1 Replies

7. Shell Programming and Scripting

Bash interactive installation script

Hi, for an exercise I need to write a script that will ask the user about each package in a (local) repository and install it or not according to the user's input. I am fairly new to scripting, so I did not get very far. Here is what I came up with. I really appreciate your help. ... (1 Reply)
Discussion started by: Softsmid
1 Replies

8. Shell Programming and Scripting

Execute interactive bash menu script in browser with PHP

I have an interactive menu script written in bash and I would like use PHP to open the interactive bash menu in a browser. Is this possible? Using the sytem() function in php runs the script but it's all garbled. Seems like maybe a terminal window needs to be opened in php first? ... (1 Reply)
Discussion started by: nck
1 Replies

9. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

10. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies
Login or Register to Ask a Question