Register now and start sharing your code snippets.
-->

Enable your favorite editor in production environment.

Shell Script (Bash) posted about 1 year ago by marko

Anyone who’s ever set up or maintained a larger production environment will love this “snippet”. Production environments seldom contain your favorite editor. In fact, most times you are stuck with vi, which is fine if that happens to be your flavor. For most people vi just doesn’t fit. The only requirement for this trick is to have SSH access into the production environment.

Firstly install sshfs on your development computer.

   1  sudo apt-get install sshfs

It should work for both major Debian derivates (Debian and various versions of Ubuntu). I know from experience that it works for Etch stable. If you don’t use a package manager then go to sshfs homepage and follow instructions from there.

Create a mountpoint for the production filesystem.

   1  sudo mkdir -p /mnt/production-xyz/bea92

Mount it with sshfs using a syntax similar to scp.

   1  sshfs marko@production_server:/opt/bea92 /mnt/production-xyz/bea92

Fire up your favorite editor and start setting up/maintaining the production environment with a smile on your face :) Once you’re done unmount it using the command below.

   1  fusermount -u /mnt/production-xyz/bea92

Tagged favorite editor, sshfs, ssh, production, linux, mounting remote directory

Remote X11 apps through SSH

Shell Script (Bash) posted about 1 year ago by marko

In order to forward X11 applications from a remote server into your local X session the server must support tunneling of X11 apps with this property in sshd_config

   1  X11Forwarding yes

Then simply issue the -X parameter for the SSH client.

   1  ssh -X remotehost

Now run an X11 application from the SSH terminal and it’s UI will be tunneled to your local X session.

   1  gvim my_script.rb

Tagged ssh, x11, remote applications, linux

Mount an ISO file in Linux

Shell Script (Bash) posted about 1 year ago by christian

   1  # mkdir /mnt/iso
   2  # mount -o loop -t iso9660 file.iso /mnt/iso

Tagged mount, iso, linux

Find out the process id of a process you know how to single out with grep.

Shell Script (Bash) posted about 1 year ago by marko

The cut program can be really versatile. Give it the character used to separate columns using the -d switch, and the column(s) you want to print using the -f switch. Here we give ’ ’ as a parameter to the -d switch because spaces indicate the columns here. A single column is given using -fn and multiple columns using -fn,n,n,n,n syntax.

   1  ps axu |grep FitNesse | grep java |grep -v grep | cut -d' ' -f3

Tagged linux, cut, pid, process id

Flushing iptables

Shell Script (Bash) posted about 1 year ago by marko

Reset all rules of iptables. Handy to put in the root’s crontab while configuring a remote firewall.

   1  #!/bin/sh
   2  # 
   3  # rc.flush-iptables - Resets iptables to default values. 
   4  # 
   5  # Copyright (C) 2001  Oskar Andreasson <bluefluxATkoffeinDOTnet>
   6  #
   7  # This program is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; version 2 of the License.
  10  #
  11  # This program is distributed in the hope that it will be useful,
  12  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  # GNU General Public License for more details.
  15  #
  16  # You should have received a copy of the GNU General Public License
  17  # along with this program or from the site that you downloaded it
  18  # from; if not, write to the Free Software Foundation, Inc., 59 Temple
  19  # Place, Suite 330, Boston, MA  02111-1307   USA
  20  
  21  #
  22  # Configurations
  23  #
  24  IPTABLES="/sbin/iptables"
  25  
  26  #
  27  # reset the default policies in the filter table.
  28  #
  29  $IPTABLES -P INPUT ACCEPT
  30  $IPTABLES -P FORWARD ACCEPT
  31  $IPTABLES -P OUTPUT ACCEPT
  32  
  33  #
  34  # reset the default policies in the nat table.
  35  #
  36  $IPTABLES -t nat -P PREROUTING ACCEPT
  37  $IPTABLES -t nat -P POSTROUTING ACCEPT
  38  $IPTABLES -t nat -P OUTPUT ACCEPT
  39  
  40  #
  41  # reset the default policies in the mangle table.
  42  #
  43  $IPTABLES -t mangle -P PREROUTING ACCEPT
  44  $IPTABLES -t mangle -P POSTROUTING ACCEPT
  45  $IPTABLES -t mangle -P INPUT ACCEPT
  46  $IPTABLES -t mangle -P OUTPUT ACCEPT
  47  $IPTABLES -t mangle -P FORWARD ACCEPT
  48  
  49  #
  50  # flush all the rules in the filter and nat tables.
  51  #
  52  $IPTABLES -F
  53  $IPTABLES -t nat -F
  54  $IPTABLES -t mangle -F
  55  #
  56  # erase all chains that's not default in filter and nat table.
  57  #
  58  $IPTABLES -X
  59  $IPTABLES -t nat -X
  60  $IPTABLES -t mangle -X
  61  

Tagged iptables, firewall, linux