Fun at work!

Blog Archives

Link

Repost: Red5 Server RTMPT with Apache as Webserver and Flowplayer Configuration

Repost: Red5 Server RTMPT with Apache as Webserver and Flowplayer Configuration

Link

Repost: Find Out What Ports Are Listening

Repost: Find Out What Ports Are Listening

How do I find open ports on Linux / FreeBSD server?

There are different commands on both Linux and UNIX server to find out what tcp/udp ports are listening or open on your own server. You can use netstat command, which print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships etc. Another (and suggested) option is to use lsof command, which list open files, and ports on Linux, FreeBSD, Solaris and other Unixish systems.

netstat command to find open ports

# netstat --listen
To display open ports and established TCP connections, enter:
$ netstat -vatn
To display only open UDP ports try the following command:
$ netstat -vaun
If you want to see FQDN (full dns hostname), try removing the -n flag:
$ netstat -vat

lsof Command Examples

To display the list of open ports, enter:
# lsof -i
To display all open files, use:
# lsof
To display all open IPv4 network files in use by the process whose PID is 9255, use:
# lsof -i 4 -a -p 9255

A Note About FreeBSD Users

You can use the sockstat command lists open Internet or UNIX domain sockets, enter:
$ sockstat
$ sockstat -l
$ sockstat -4 -l
$ sockstat -6 -l

Link

Repost: “Local DNS Settings: Map a Domain to a Local IP Address”

Repost: “Local DNS Settings: Map a Domain to a Local IP Address”

Edit the Hosts File in Windows

1. Open the Hosts file in Notebook or some other simple text editor editor. Where is the hosts file you ask? Depends on your setup, but for most Windows systems the directory path should be something like

\\Windows\System32\drivers\etc\hosts

Depending on your security settings, you may need to open your text editor in administrator mode (‘run as administrator’) in order to save your edits.

2. At the top of the file there are instructions for how to use the file, all preceeded by the # comment tags.

3. Below this are the actual mappings. The first column contains the preferred IP destination, while the second column contains the domain to be mapped. The domains in the second column will resolve to the corresponding IPs in the first column. A few important points:

  • Naked domains and subdomains (i.e., www.) must be mapped separately.
  • You must use an IP address in the first column, not another domain name.
  • Use hashes to disable mappings temporarily

4. Once you’ve made your settings, save the file.

5. Open the Command Prompt and update your system’s DNS cache with the command:

ipconfig /flushdns

6. All browsers should now follow these mappings for the domains listed in this Hosts file.

Edit the Hosts File on a Mac OSX

1. Open Terminal and open the hosts file using the following command:

sudo nano /private/etc/hosts 

2. You may be asked to enter your administrator password. Go ahead and do that to continue.

3. The Hosts file will open. Much like the Windows version, there are instruction comments at the top, followed by the mappings. The first column contains the preferred IP destination, while the second column contains the domain to be mapped. The domains in the second column will resolve to the corresponding IPs in the first column.

4. Add your new mappings. Just as with the Windows version, keep in mind that:

  • Naked domains and subdomains (i.e., www.) must be mapped separately.
  • You must use an IP address in the first column, not another domain name.
  • Use hashes to disable mappings temporarily

5. When finished save your changes by pressing Control-o, then hit return to confirm the filename, then Control-x to close the Hosts file.

6. Lastly, update your DNS cache from Terminal using the command:

dscacheutil -flushcache

7. All browsers should now follow these mappings for the domains listed in this Hosts file.

Link

Repost: Subversion Tutorial: 10 Most Used SVN Commands with Examples

Repost: Subversion Tutorial: 10 Most Used SVN Commands with Examples

Subversion is a free/open-source version control system. Subversion manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to your files and directories. This allows you to recover older versions of your code, or examine the history of how your code was changed.

Read more…

 

Link

Repost: “Shell Scripting: Convert Uppercase to Lowercase”

Repost: “Shell Scripting: Convert Uppercase to Lowercase”

Use the tr command to convert all incoming text / words / variable data from upper to lower case or vise versa (translate all uppercase characters to lowercase). Bash version 4.x+ user can use parameter expansion to modify the case of alphabetic characters in parameter.

Convert all text in a file from UPPER to lowercase

To translate or delete characters use tr command. The basic syntax is:

tr 'set1' 'set2' input

OR

tr 'set1' 'set2' input > output

Type the following command at shell prompt:
$ tr '[:upper:]' '[:lower:]' < input.txt > output.txt
$ cat output.txt

Task: Convert Data Stored in a Shell Variable From UPPER to lowercase:

Type the following command:
$ echo $VAR_NAME | tr '[:upper:]' '[:lower:]'
$ echo $VAR_NAME | tr '[:lower:]' '[:upper:]'

Bash version 4.x+: Uppercase to lowercase or vice versa

The bash version 4.x+ got some interesting new features. Type the following commands to convert $y into uppercase:

 
y="this Is A test"
echo "${y^^}"

Sample outputs:

THIS IS A TEST

Type the following commands to convert $y into lowercase:

 
y="THIS IS a TeSt"
echo "${y,,}"

Sample outputs:

this is a test

Sample Shell Script

#!/bin/bash
# get filename
echo -n "Enter File Name : "
read fileName

# make sure file exits for reading
if [ ! -f $fileName ]; then
  echo "Filename $fileName does not exists."
  exit 1
fi

# convert uppercase to lowercase using tr command
tr '[A-Z]' '[a-z]' < $fileName

# Note Bash version 4 user should use builtins as discussed above
Link

Repost: 10 Practical Linux Cut Command Examples to Select File Columns

Repost: 10 Practical Linux Cut Command Examples to Select File Columns

Linux command cut is used for text processing. You can use this command to extract portion of text from a file by selecting columns.

This tutorial provides few practical examples of cut command that you can use in your day to day command line activities.

For most of the example, we’ll be using the following test file.

$ cat test.txt
cat command for file oriented operations.
cp command for copy files or directories.
ls command to list out files and directories with its attributes.

1. Select Column of Characters

To extract only a desired column from a file use -c option. The following example displays 2nd character from each line of a file test.txt

$ cut -c2 test.txt
a
p
s

As seen above, the characters a, p, s are the second character from each line of the test.txt file.

2. Select Column of Characters using Range

Range of characters can also be extracted from a file by specifying start and end position delimited with -. The following example extracts first 3 characters of each line from a file called test.txt

$ cut -c1-3 test.txt
cat
cp
ls

3. Select Column of Characters using either Start or End Position

Either start position or end position can be passed to cut command with -c option.

 

The following specifies only the start position before the ‘-’. This example extracts from 3rd character to end of each line from test.txt file.

$ cut -c3- test.txt
t command for file oriented operations.
 command for copy files or directories.
 command to list out files and directories with its attributes.

The following specifies only the end position after the ‘-’. This example extracts 8 characters from the beginning of each line from test.txt file.

$ cut -c-8 test.txt
cat comm
cp comma
ls comma

The entire line would get printed when you don’t specify a number before or after the ‘-’ as shown below.

$ cut -c- test.txt
cat command for file oriented operations.
cp command for copy files or directories.
ls command to list out files and directories with its attributes.

4. Select a Specific Field from a File

Instead of selecting x number of characters, if you like to extract a whole field, you can combine option -f and -d. The option -f specifies which field you want to extract, and the option -d specifies what is the field delimiter that is used in the input file.

The following example displays only first field of each lines from /etc/passwd file using the field delimiter : (colon). In this case, the 1st field is the username. The file

$ cut -d':' -f1 /etc/passwd
root
daemon
bin
sys
sync
games
bala

5. Select Multiple Fields from a File

You can also extract more than one fields from a file or stdout. Below example displays username and home directory of users who has the login shell as “/bin/bash”.

$ grep "/bin/bash" /etc/passwd | cut -d':' -f1,6
root:/root
bala:/home/bala

To display the range of fields specify start field and end field as shown below. In this example, we are selecting field 1 through 4, 6 and 7

$ grep "/bin/bash" /etc/passwd | cut -d':' -f1-4,6,7
root:x:0:0:/root:/bin/bash
bala:x:1000:1000:/home/bala:/bin/bash

6. Select Fields Only When a Line Contains the Delimiter

In our /etc/passwd example, if you pass a different delimiter other than : (colon), cut will just display the whole line.

In the following example, we’ve specified the delimiter as | (pipe), and cut command simply displays the whole line, even when it doesn’t find any line that has | (pipe) as delimiter.

$ grep "/bin/bash" /etc/passwd | cut -d'|'  -f1
root:x:0:0:root:/root:/bin/bash
bala:x:1000:1000:bala,,,:/home/bala:/bin/bash

But, it is possible to filter and display only the lines that contains the specified delimiter using -s option.

The following example doesn’t display any output, as the cut command didn’t find any lines that has | (pipe) as delimiter in the /etc/passwd file.

$ grep "/bin/bash" /etc/passwd | cut -d'|' -s -f1

7. Select All Fields Except the Specified Fields

In order to complement the selection field list use option –complement.

The following example displays all the fields from /etc/passwd file except field 7

$ grep "/bin/bash" /etc/passwd | cut -d':' --complement -s -f7
root:x:0:0:root:/root
bala:x:1000:1000:bala,,,:/home/bala

8. Change Output Delimiter for Display

By default the output delimiter is same as input delimiter that we specify in the cut -d option.

To change the output delimiter use the option –output-delimiter as shown below. In this example, the input delimiter is : (colon), but the output delimiter is # (hash).

$ grep "/bin/bash" /etc/passwd | cut -d':'  -s -f1,6,7 --output-delimiter='#'
root#/root#/bin/bash
bala#/home/bala#/bin/bash

9. Change Output Delimiter to Newline

In this example, each and every field of the cut command output is displayed in a separate line. We still used –output-delimiter, but the value is $’\n’ which indicates that we should add a newline as the output delimiter.

$ grep bala /etc/passwd | cut -d':' -f1,6,7 --output-delimiter=$'\n'
bala
/home/bala
/bin/bash

10. Combine Cut with Other Unix Command Output

The power of cut command can be realized when you combine it with the stdout of some other Unix command.

Once you master the basic usage of cut command that we’ve explained above, you can wisely use cut command to solve lot of your text manipulation requirements.

The following example indicates how you can extract only useful information from the ps command output. We also showed how we’ve filtered the output of ps command using grep and sed before the final output was given to cut command. Here, we’ve used cut option -d and -f which we’ve explained in the above examples.

$ ps axu | grep python | sed 's/\s\+/ /g' | cut -d' ' -f2,11-
2231 /usr/bin/python /usr/lib/unity-lens-video/unity-lens-video
2311 /usr/bin/python /usr/lib/unity-scope-video-remote/unity-scope-video-remote
2414 /usr/bin/python /usr/lib/ubuntuone-client/ubuntuone-syncdaemon
2463 /usr/bin/python /usr/lib/system-service/system-service-d
3274 grep --color=auto python
Link

Repost: How to Delete Symbolic Link

Repost: How to Delete Symbolic Link

You can use any one of the following command to remove symbolic links:

  • rm – removes each given FILE including symbolic links
  • unlink – deletes a single specified file name including symbolic links.

Delete Symbolic Link File

Use the following syntax:

 
rm linkname
unlink linkname

Cd to /tmp

cd /tmp
ln -s /etc/resolv.conf dns
ls -l dns

Outputs:

lrwxrwxrwx 1 vivek vivek 16 2009-08-16 04:28 dns -> /etc/resolv.conf

Now delete dns symbolic link:

 
rm dns

OR

unlink dns

Delete Symbolic Link Directory

Use the following syntax:

 
rm linkDirName
unlink linkDirName

Note: Avoid appending / at the end of linkDirName. Cd to /tmp:

cd /tmp
ln -s /etc test
ls -l test

Sample Output:

lrwxrwxrwx 1 vivek vivek 4 2009-08-16 04:31 test -> /etc

Now delete test symbolic link directory:

 
rm test

OR

unlink test
Link

Repost: Linux / Unix: Checking Free Disk Space

Repost: Linux / Unix: Checking Free Disk Space

Q. How do I check free disk space in Linux or UNIX operating system? I’ve migrated from Windows NT to Linux and looking forward to get more information about free disk space.

A. Both Linux and UNIX offers two commands for checking out free disk space:

(a) df command : Report file system disk space usage

(b) du command : Estimate file space usage

Read more…

Link

Repost: Linux Check Memory Usage

Repost: Linux Check Memory Usage

How do I check used and free RAM memory usage under Linux operating systems using command line and GUI tools?

Linux comes with different set of commands to check memory usage. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity. Finally, you can use the top, and/or atop/htop commands which provides a dynamic real-time view of a running system. top and friends can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

Read more…

 

Link

Report: Making sense of memory usage on Linux

Report: Making sense of memory usage on Linux

Let’s look at some basic commands that report on memory usage. The first that probably comes to mind is free. The free command will tell you about used and unused memory and about swap space. Physical memory is the random access storage provided by the RAM modules plugged into your motherboard. Swap is some portion of space on your hard drive that is used as if it is an extension of your physical memory.

Read more…