Hi all, new to the forum and rusty with my scripting. I am trying to put together a quick and dirty script that will kickoff a tcpdump on multiple machines. Then, another script that will reach out (at a later time) to stop the processes and retrieve the data. It seems fairly easy conceptually and will most likely consist of repeating lines with different username@<ip addresses> so I am trying to get just one to work for now.
Digging around the interweb has simply confused me and I could really use some help.
The usernames for the machines all have passwords (sorry, using keys is not an option) so I was looking at using expect like:
Obviously, this does not work or I wouldn't be here. In this case, the script runs but when I look on the server, tcpdump is not running. I had tried using "interact" after the password and removing the & but that just left my script hanging and not moving on to kickoff the next tcpdump.
In this case, the script runs but when I look on the server, tcpdump is not running.
The problem is not your script but the way UNIX is working: when a process starts it is assigned a terminal - usually the one it was started at. Once this terminal goes away the process ist terminated too. Now, you log on to a system by using ssh. That you do it from a script doesn't matter at all. Inside this session you start a program - tcpdump - and then kill the session. This way, the terminal ceases to exist and therefore the program is terminated too.
You probably thought that you prevented that by sending the process to background, but this is not the case. What you need (in addition to sending it to background) is the nohup keyword. "nohup" is short for "no termination on hangup" and it prevents exactly that behavior: the process will not be terminated once the terminal goes away (the session "hangs up" - this is from the time when sessions were serial lines and mostly dial-up).
If you do it with "interact" your script doesn't hang at all: it is executing the "ssh"-command but since this is never terminated it will never get to the next command. Therefore it seems to hang.
Still i'd like to suggest that you forego the whole business with expect. Instead of writing passwords in clear-text into your script (it doesn't matter if they come from a file or your scripts text directly - clear-text is clear-text and whatever encryption you will use the script will have to decrypt it automatically) you should exchange ssh-keys for the system-/user-combinations you want to process and use these. Then you can just build a textfile with the systems and users and your script will be a simple loop, like this:
One last thing: if you use nohup you should expressly redirect all possible output of the process, e.g.
because otherwise any output would be sent by mail (!) to either the user or root internally. You don't want that.
I've recently started learning to use TCPdump, and I find it pretty interesting. There's one thing I don't understand. When I tell it to capture packets on, say, the WiFi interface en1, it often captures packets sent or received by other hosts on the network. How can it do this? My... (3 Replies)
Hi Folks ,
I have a query that is I have a server (unix machhine) to which I login thru winscp or putty , mostly I use putty and at a particular location there is one xml(abc.xml) while which I change , let say
1) I login to first unix box
hostname :- ccc74
username ... (1 Reply)
Hi All, I have been a guest visitor from a long time and this forum is wonderful. I finally am a member of this forum too, so i am here stuck with a shell script that i was trying to write
My requirement is that i should be able to create a shell script which will check if a process is running on... (3 Replies)
I want a script that would do as:-
a) gives me packet capture account for each time it runs.
b) be able to run at a particular time for specific period time duration (1 min).
c) for each time it runs it saves the time / day.
Is there a way where i can capture the details as seen in the... (2 Replies)
Hi all
I have to run certain set of commands on two machines, the two machines see the same home, it's mounted from the same place. The problem is that i have to ssh to a certain machine "which is slow unfortunately" that has the license to run a tool and i want to return to the original machine... (3 Replies)
I'm new to the Unix/Linux world. I have taken classes and played with a few simple scripts but never had a real world application. Here is my problem.
What I need to do is every 15min between 8am and 5pm, run
tcpdump -s 2000 -w flowroute-0000.pcap
where the "0000" is the current time.
... (4 Replies)
i am trying to write a script to parse some tcpdump output, in each line of the tcpdump output, I know for sure there are 3 keywords exist:
User{different usernamehere}
NAS_ipaddr{different ip here}
Calling_station{ip or dns name here}
But the positions for these 3 keywords in the... (4 Replies)
Greetings, I just started using scripting languages,
im trying to get a tcpdump in a file, change the
file name every 5mins ... this is what i have but its
not working ... any suggestions?
#!/bin/bash
# timeout.sh
#timestamp format
TIMESTAMP=`date -u "+%Y%m%dT%H%M%S"`
#tdump =`tcpdump... (3 Replies)
To clear the web cache on my web server, I run this command:
find $APACHE_HOME/cache/plsql/plsql -type d -name "*" -exec rm -R {} \;
To clear the cache on all the web servers(we have 4), I log on to any one machine, clear its cache, ssh to another machine, clear cache etc;
Is there any way... (8 Replies)
I have two net-card. one is 172.16.24.99(ENG) ,another is 172.16.25.99(ENG-B). Both masks is 255.255.255.0.
I will monitor data on the tcp port 8055 in ENG, How do I set option of tcpdump command (2 Replies)