Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Monday, November 11, 2013

screen - screen manager with VT100/ANSI terminal emulation

Ctrl a c - New window
Ctrl a n - Next window
Ctrl a p - Previous window
Ctrl a d - detach
Ctrl a k - Kill window

screen -ls - List sessions
screen -r <number> reattach

Thursday, September 2, 2010

Listing Multicast group memberships

In Windows XP:

C:\>netsh interface ip show joins


Interface Addr   Multicast Group
---------------  ---------------
172.17.17.223    224.0.0.1
172.17.17.223    239.255.255.250

In Solaris and other UNIXes:


$ netstat -gn
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
eth0            1      224.0.0.1
lo              1      ff02::1
eth0            1      ff02::1:ff09:ac30
eth0            1      ff02::1

Monday, August 30, 2010

The Three UNIX File Times

access time - cat myfile # read
ls -Elu

modification time - echo "Hello, World!" > myfile # writing
ls -El

change time - chmod a+w myfile # inode's update
ls -Elc

Tuesday, April 13, 2010

Number of days in current Month in UNIX shell

cal | grep -v '[A-Za-z]' | wc -w

Last Sunday of the Month in UNIX shell

cal | grep '^[23]' | tail -1 | cut -d' ' -f1

Several months later I don't remember why the grep part?

cal | tail -1 | cut -d' ' -f1


AWK version:



#!/bin/bash


cal | awk '
    { last = $1 }
END { print last }'


##END##

Thursday, September 18, 2008

PCP - Show open ports and PIDs on Solaris

Ayer me encontré este script que me pareció muy bueno para Solaris.

El sitio del autor es: http://www.unix.ms/pcp/

#!/usr/bin/ksh
#
# PCP (PID con Port)
# v1.07 20/05/2008 sam@unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# The script borrows Eric Steed's excellent "getport.sh" script.
#
if [ $# -lt 1 ]
then
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a ALL ] (Wildcards OK)"
exit 1
fi
while getopts :p:P:a opt
do
case "${opt}" in
p ) port=${OPTARG};;
P ) pid=${OPTARG};;
a ) all=all;;
[?]) # unknown flag
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a ALL ] (Wildcards OK) "
exit 1;;
esac
done
shift `expr $OPTIND - 1`
if [ $port ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a grep -v ptree awk '{print $1};'`
do
result=`pfiles $proc 2> /dev/null grep "port: $port"`
if [ ! -z "$result" ]
then
program=`ps -fo comm -p $proc tail -1`
echo "$proc\t$program\t$port\n$result"
echo "_________________________________________________________"
fi
done
elif [ $pid ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a grep -v ptree grep $pid awk '{print $1};'`
do
result=`pfiles $proc 2> /dev/null grep port:`
if [ ! -z "$result" ]
then
program=`ps -fo comm -p $pid tail -1`
echo "$proc\t$program\n$result"
echo "_________________________________________________________"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for pid in `ptree -a grep -v ptree sort -n awk '{print $1};'`
do
out=`pfiles $pid 2>/dev/null grep "port:"`
if [ ! -z "$out" ]
then
name=`ps -fo comm -p $pid tail -1`
echo "$pid\t$name\n$out"
echo "_________________________________________________________"
fi
done
fi
exit 0