Archive for the 'Shell' Category

Accessing Samba Share from Console

Jun 20 2011 Published by under Samba,Shell

First, list all shared folders on a remote computer

$ smbclient -L 192.168.1.16

Response looks like this:

Enter haris's password:
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.34]

	Sharename       Type      Comment
	---------       ----      -------
	Public          Disk      My Public folder

Then hook right to Public folder, for example

$ smbclient //192.168.1.16/Public

After successful login, you will get a command prompt.

Enter haris's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.34]
smb: \> ls
  .                                   D        0  Fri Jun 17 09:02:43 2011
  ..                                  D        0  Fri May 20 00:44:39 2011

Type help to display all available commands

Comments Off

Init-d Template

May 28 2011 Published by under Shell

Create a new file

$ sudo vim /etc/init.d/$NAME

Change the template to suit your needs

#!/bin/bash

case "$1" in
  start)
           # start commands here
        ;;
  stop)
           # stop commands here
        ;;
  restart)
           # restart commands here
        ;;
  *)      # no parameter specified
        echo "Usage: /etc/init.d/$NAME start|stop|restart"
        exit 1
        ;;
esac
exit 0

Hook the script to all runlevels

$ sudo update-rc.d $NAME defaults

Comments Off

Swap File

May 21 2011 Published by under Shell,Ubuntu

To create swap space in a file:

First, create a file. I have 4GB of RAM, hence I create 4GB large file

$ sudo dd if=/dev/zero of=/media/4GB.swap bs=1G count=4

Set proper file attributes

$ sudo chmod 600 /media/4GB.swap

Set created file as a swap space

$ sudo mkswap /media/4GB.swap

Start swapping

$ sudo swapon /media/4GB.swap

Edit the fstab file

$ sudo vim  /etc/fstab

and set the swap file to mount automatically on next reboot

/media/4GB.swap	swap		swap		defaults	0	0

Comments Off

The simplest, yet most powerful VIM configuration line

Apr 17 2011 Published by under Misc,Shell

./configure --with-features=big

Comments Off

Nohup and Screen

Apr 11 2011 Published by under Shell

I always thought that when you create a process from terminal, and move it to background with &, that It was supposed to stay in background, right?

Well, the problem is that processes that output data back to terminal, when you close the terminal, will close the processes created in it as well.

In order to resolve this issue, just type ‘nohup’ in front of the command you want to run in background and that solves the problem.

The other way is to use a screen command.

Screen basically detaches the terminal session and puts it in background.

You can always come back later, or even ssh to a remote box and return back to a terminal session, right where you left it with ‘screen -r’

Comments Off

SSH SOCKS proxy server

Jan 04 2011 Published by under Security,Shell

If you crave for privacy and wish to protect your communications (like chat and email) from prying eyes, this is how dynamic port forwarding can turn SSH into a SOCKS proxy server.

The idea is to forward all traffic from @unsecure to @secure location via SSH and then use Internet from @secure location.

To set up a proxy run

ssh -C -D 1080 user@SecureLocation.com

-C enables compression
-D 1080 runs dynamic port forwarding on port 1080

After you connect to secure location, edit browser, email or chat SOCKS proxy settings, pointing them to ‘localhost:1080‘ and use your apps without worrying of being snooped.

Comments Off

Stop cron emails

Nov 23 2010 Published by under Shell

When you run a cron job that returns some output, that output is sent back to the user that created the cron job.

In order to stop receiving email notifications just add “>/dev/null 2>&1” at the end of your cron command line.

For example

0 * * * * ls ~ >/dev/null 2>&1

Comments Off

Performance Optimization WordPress Plugins by W3 EDGE