The UNIX and Linux Forums  

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
function returns string lalelle Shell Programming and Scripting 5 08-23-2007 06:16 PM
first value of array returns blank Sudhakar333 Shell Programming and Scripting 1 08-06-2007 10:16 AM
vmstat returns good val for cpuIdle put ps shows no active process OFFSIHR Shell Programming and Scripting 5 04-09-2007 02:01 PM
longjmp never returns axes High Level Programming 2 09-10-2006 09:22 PM
inet_addr() returns 0 soulfactory2002 High Level Programming 1 06-02-2005 05:25 PM

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 11-28-2005
smtpgeek smtpgeek is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 11
process grepping returns itself

I am trying to write a script to make a ssh tunnel persist. I am writing it to check the existence of the tunnel on port 3307 and if it is not found start it:

#!/usr/local/bin/bash
# ~/my_tunnel.sh
tunnel_up=`ps ax|grep 3307`
if [ "${tunnel_up}" = "" ]; then
ssh -fNg -C -L 3307:127.0.0.1:3306 bob@db.webstakez.com & 2>/dev/null
fi

I believe that this is not working because the grep is returning a value for the actual grep command even when the tunnel is down. As an example, I check for anything on port 3308 since the tunnel is up:

$ ps waux|grep 3308
10014 18755 0.0 0.0 1428 440 pts/0 S 12:53 0:00 grep 3308

This is a Linux system, 2.4.20-021stab028.3.777-enterprise #1 and grep does not act this way on my freebsd box. What can I do to so that this will not return the actual grep?

TIA,
Bob
  #2 (permalink)  
Old 11-28-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
try something like

Code:
tunnel_up=`ps ax|grep 3307 | grep -v 'grep'`

which will filter out the current grep call
  #3 (permalink)  
Old 11-28-2005
smtpgeek smtpgeek is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 11
namaste'

Quote:
Originally Posted by jim mcnamara
try something like

Code:
tunnel_up=`ps ax|grep 3307 | grep -v 'grep'`

which will filter out the current grep call
Perfecto!!

Thanks for the insight.

/bob
  #4 (permalink)  
Old 11-28-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
or you could:
tunnel_up=`ps ax|grep [3]307`
  #5 (permalink)  
Old 11-14-2007
hasen_a hasen_a is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 1
my tunnel

I am trying to get something similar established. The following code is ~/bin/mytunnel.sh

Code:
#!/bin/sh
# ~/bin/my_tunnel.sh
tunnel_up=`ps ax|grep 1080 | grep -v 'grep'`
if [ "${tunnel_up}" = "" ]; then
ssh -D 127.0.0.1:1080 andyhase@tripleyou.dyndns.org & &0 < 'password'
fi

I would like to have the script insert the password via stdin when the password question of ssh comes up. As of right now I get the error message:
Code:
 5: Syntax error: "&" unexpected

Thanks, Andreas
Closed Thread

Bookmarks

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 05:49 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