Trying to run a script over ssh, having issues with tty assignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to run a script over ssh, having issues with tty assignment
# 1  
Old 12-27-2008
Trying to run a script over ssh, having issues with tty assignment

Hey folks! I'm trying to run a tcpdump command that monitors for possible malicious traffic. I want to be able to run this on any of several remote boxes that I monitor which all have different capture interfaces. I've gotten the script to the point where it logs into the box and attempts to run the commands but the capif command is giving me problems.


If I'm ssh'ing into the sensor myself the same series of commands works fine. I could create a scriptfile on each of the sensors and have this script run that but there's a lot of them.

Last edited by JASI; 06-08-2009 at 11:12 AM..
# 2  
Old 12-27-2008
Quote:
Originally Posted by JASI
: Invalid argument
This is the capture interface:
tcpdump: ioctl: No such device

As always, the first thing to do is to read any error messages and fix their cause.

Why is capif not found? Does the command exist?

Is it not in your PATH? If not, why not?

Once you have solved that problem, post the smallest possible example of code that exhibits any remaining problems.
# 3  
Old 12-28-2008
I believe that whats happening is that the script is attempting to run capif on the box that I'm running the script on instead of running capif on the remote box that I'm ssh'ing into.

As I said, if I put those commands in a script and run them on the remote box after having ssh'd into the box then it works just fine.

While playing around with it I found that using ssh -t -t gets rid of the
/whilemenu: line 24: capif: command not found
Pseudo-terminal will not be allocated because stdin is not a terminal.
mesg: ttyname

error and replaces it with an error:
tcgetattr: Inappropriate ioctl for device

Again, if I create the script on the remote box and either ssh to the box manually and run it or ssh via the scrip and call the 2nd script on the remote box it works as intended.

So whatever the problem is it's something to do with interactivity of ssh from what I can tell.
# 4  
Old 12-28-2008
Okay, I fiddled some more and I think that the problem is actually that since I'm using a here document, it's reading the lines of the doc off to the remote box as if they were individual commands instead of pieces of a script.

So I guess what i need is a way to get the remote box to have the lines interpreted as a shell script instead of individual commands.

Any thoughts?
# 5  
Old 12-28-2008
Quote:
Originally Posted by JASI
Okay, I fiddled some more and I think that the problem is actually that since I'm using a here document, it's reading the lines of the doc off to the remote box as if they were individual commands instead of pieces of a script.

Try quoting the here-document delimiter:

Code:
ssh -t -p 33233 $sensor<<-"LimitString"

Quote:
So I guess what i need is a way to get the remote box to have the lines interpreted as a shell script instead of individual commands.

A collection of individual commands is a shell script.
# 6  
Old 12-29-2008
A script may indeed be a collection of commands, but I'm sure you'll agree that there are things that you can do in a shell script that simply don't work when entered as simple commands from the terminal. At least not with the same syntax. Smilie For example, variable assignment.

Adding the double quotes to the here document delimiter doesn't appear to have changed anything except to cause the
Code:
interface='capif';

line to be interpreted as assigning the string capif to the interface variable.

That seems to be the main problem at this point, I need to get the output of capif assigned to the variable interface so that I can run tcpdump on the appropriate capture interface which varies from box to box.
# 7  
Old 12-29-2008
MySQL

Hah! Fixed it.

Code:
interface=$(capif);

Which I had tried before but without the double quotes around the LimitString delimiter. By the way, what is it about doing that which changed the way shell interpreted it?

Thanks for the help!

Last edited by JASI; 12-29-2008 at 01:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues while trying to run a shell script using the command sh <filename.prog>

Hi, I'm facing issues while trying to run a sample program on Linux. If I try to run the script using the command "sh <filename.prog>", it doesn't work. But, if I try to execute it using the command "ksh <filename.prog>", it works fine. Even ". ./filename.prog" works fine. Can you... (6 Replies)
Discussion started by: venkatesh17
6 Replies

2. Shell Programming and Scripting

Remote script over ssh execution issues.

If I execute below code I am able to get string from column8 and column10 about a process. serverA1$> ps -ef | grep rotate | grep 'config' | awk '{print $8" "$10}' /<Oracle_home>/ohs/bin/odl_rotatelogs -h:/<app_Home>/config/OHS/ohs1/component_events.xml_ohs1... (12 Replies)
Discussion started by: kchinnam
12 Replies

3. Shell Programming and Scripting

Perl program to run a Shell script issues...

Hi all, I have the following Perl script which is intended to run a Shell script and generate some logging for the purposes of tracking weather or not the script ran. I get an error, of course, since I don't know what I'm doing really. Here is the code: #!/opt/perl/bin/perl -w ... (14 Replies)
Discussion started by: zixzix01
14 Replies

4. UNIX for Advanced & Expert Users

Access to Remote tty cli via ssh

Scenario: I would like the ability to be able to use the cli on a client that has remotely connected to me via my ssh server in my office and use their terminal to work remotely if I am in another remote location. Ex. The client reverse ssh's to my remote ssh server in my office. ssh... (5 Replies)
Discussion started by: metallica1973
5 Replies

5. Shell Programming and Scripting

ssh run script error

Hello when try to excute the following ssh -l pla 10.287.60.55 vis_fil vis_fil not found. but it works fine when login to the server. can you help me run this command in one online because i will add later to shell script regards (1 Reply)
Discussion started by: mogabr
1 Replies

6. Shell Programming and Scripting

ssh - run shell script - Error

Hi Team, I am trying to run shell script from one server to another server with below command. ssh abc@pqr.america.com /tmp/test.ksh But, it gives below error. Can someone help me what is the issue? exec(): 0509-036 Cannot load program ssh because of the following errors: ... (3 Replies)
Discussion started by: ace_friends22
3 Replies

7. Shell Programming and Scripting

ssh to run bash script

I want to use ssh to start a bash script that I have uploaded to a webhost. How do I do that from linux? (2 Replies)
Discussion started by: locoroco
2 Replies

8. OS X (Apple)

No terminal (tty) after ssh and telnet also

Hi all, we are just confused about a strange problem on one server in production (XServer, running OSXS 10.5.6). It works normal for month. Since two day everthing seems to be fine also with one exception. When we connect trough ssh we won't get a tty session. For testing purposes, we enabled... (2 Replies)
Discussion started by: Frank.Knobloch
2 Replies

9. AIX

Tty Over Run

dears i have two IBM p630 application servers, they are running hacmp 5.2 as the clustering software. from the output of errpt on one of the nodes i am receiving the following error: 9D30B78E 0530020007 T S tty1 RECEIVER OVER-RUN ON INPUT please are there any ideas about how... (0 Replies)
Discussion started by: TheEngineer
0 Replies

10. Shell Programming and Scripting

Issues using ssh from crontab to run remote script from

I have a solaris9 x86 server using ssh as follows: SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0. The remote server solaris9 sparc has exactly the same version ssh installed. I am running a script on my server which includes the following command to run a script on the remote server:... (4 Replies)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question