The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Telnet Script Issues Darknight Shell Programming and Scripting 10 02-09-2009 03:09 PM
shell script programming issues FSUdude08 UNIX for Dummies Questions & Answers 3 12-01-2008 03:08 AM
SFTP / UNZIP script issues Peanutz Shell Programming and Scripting 0 11-06-2008 10:49 AM
2 script for assignment. snyper2k2 UNIX for Dummies Questions & Answers 1 04-10-2006 12:07 PM
Issues using ssh from crontab to run remote script from frustrated1 Shell Programming and Scripting 4 08-25-2005 03:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-27-2008
JASI JASI is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
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 10:12 AM..
  #2 (permalink)  
Old 12-27-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by JASI View Post
: 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 (permalink)  
Old 12-28-2008
JASI JASI is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
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 (permalink)  
Old 12-28-2008
JASI JASI is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
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 (permalink)  
Old 12-28-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by JASI View Post
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 (permalink)  
Old 12-29-2008
JASI JASI is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
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. 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 (permalink)  
Old 03-25-2009
sankad sankad is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 1
Thumbs up

This was a life saver for me.Thanks a lot cfajohnson & JASI.

Check this simple example.

#!/bin/bash
ssh -T root@192.168.0.2 << "EOF"
MYDATE=`date`
echo $MYDATE
EOF

Closed Thread

Bookmarks

Tags
inappropriate ioctl for device

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0