Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created December 26, 2010 13:31
Show Gist options
  • Save shripadk/755422 to your computer and use it in GitHub Desktop.
Save shripadk/755422 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
## REDIS REMOTE CONNECTOR
##
## Edit these values to reflect the authentication credentials for the
## server running the instance with which you wish to
## modify the `$remote_port` value. You should not need to modify the
## `$remote_ip` value.
##
$remote_user = "ubuntu";
$remote_host = "beta.accelsor.com";
$remote_port = "6379";
$remote_ip = "127.0.0.1";
##
## Modify these values only if you are running a local
## instance.
##
$local_ip = "127.0.0.1";
$local_port = "6379";
##
## You do not need to edit this file beyond this point.
##
$a = shift;
$a =~ s/^\s+//;
$a =~ s/\s+$//;
$pid=`ps ax|grep ssh|grep $local_port|grep $remote_port`;
$pid =~ s/^\s+//;
@pids = split(/\n/,$pid);
foreach $pid (@pids)
{
if ($pid =~ /ps ax/) { next; }
split(/ /,$pid);
}
if (lc($a) eq "start")
{
if ($_[0]) { print "Redis tunnel already running.\n"; exit 1; }
else
{
system "ssh -f -L $local_ip:$local_port:$remote_ip:$remote_port $remote_user\@$remote_host -N";
exit 0;
}
}
elsif (lc($a) eq "stop")
{
if ($_[0]) { kill 9,$_[0]; exit 0; }
else { exit 1; }
}
else
{
print "Usage: redistunnel.pl [start|stop]\n";
exit 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment