Wednesday, November 23, 2011

Solaris: calculate diff filesystem size after transfer

#! /bin/sh
value1=`df -k /app/iwstoreEMEA_snap| grep snap| awk '{print $3}'`
value2=`df -k /server4_EMEA | grep _EMEA | awk '{print $3}'`
exprans=`expr $value1 - $value2`
echo "$exprans kb left"
sleep 60
value1=`df -k /app/iwstoreEMEA_snap| grep snap| awk '{print $3}'`
value2=`df -k /server_EMEA | grep _EMEA | awk '{print $3}'`
exprans1=`expr $value1 - $value2`
transfer=`expr $exprans - $exprans1`
echo "$transfer KB transferd"


$ sh a.sh
42318487 kb left
14891 KB transferd



Solaris: ssh tunnel and nc file transfer

You pipe the file to a listening socket on the server machine in the same way as before. It is assumed that an SSH server runs on this machine too.

$ cat backup.iso | nc -l 3333
On the client machine connect to the listening socket through an SSH tunnel:

$ ssh -f -L 23333:127.0.0.1:3333 me@192.168.0.1 sleep 10; \
        nc 127.0.0.1 23333 | pv -b > backup.iso

This way of creating and using the SSH tunnel has the advantage that the tunnel is automagically closed after file transfer finishes. For more information and explanation about it please read my article about auto-closing SSH tunnels.

Solaris: ssh and tar

How to transfer directories into remote server using tar and ssh combined.
$ tar cf - mydir/ | ssh gate 'cd /tmp && tar xpvf -'

Monday, November 21, 2011

Sendmail: how to masquarate from oracle@host.domain.com to oracle@domain.com

root@wbitdb1:/etc/mail # diff sendmail.cf sendmail.cf.21012008
986,987c986
< #R$* < @ *LOCAL* > $* $: $1 < @ $j . > $2
< R$* < @ *LOCAL* > $*  $: $1 < @ $M . > $2
---
> R$* < @ *LOCAL* > $*  $: $1 < @ $j . > $2
root@wbitdb1:/etc/mail #


add the line shown below
--------------
###################################################################
###  Ruleset 94 -- convert envelope names to masqueraded form   ###
###################################################################

SMasqEnv=94
#R$* < @ *LOCAL* > $*   $: $1 < @ $j . > $2 <--------------- this line commented
R$* < @ *LOCAL* > $*    $: $1 < @ $M . > $2 <--------------- this line added


----------
Testing masquerading
sendmail's address test mode makes it easy to test masquerading.
====================================================

# sendmail -bt
/tryflags HS (to test the header sender address; other tryflags values would be ES, HR, and ER, for envelope sender, header recipient, and envelope recipient, respectively)
/try esmtp email_address_to_test

Example:
sendmail -bt
> /tryflags ES
> /try esmtp user@host.domain.com
Trying envelope sender address user@host.domain.com for mailer esmtp

(many lines omitted)

final            returns: user @ domain . com
Rcode = 0, addr = user@domain.com

Saturday, November 19, 2011

Solaris: Other tunnelling tricks

Connect to port 42 of host.example.com via an HTTP proxy at 10.2.3.4, port 8080. 
This example could also be used by ssh(1); see the ProxyCommand directive in ssh_config(5) for more information.

$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42

Solaris: simple port scanning

PORT SCANNING

It may be useful to know which ports are open and running services on a target machine. The -z flag can be used to tell nc to report open ports, rather than initiate a connection. For example:

$ nc -z host.example.com 20-30
Connection to host.example.com 22 port [tcp/ssh] succeeded!
Connection to host.example.com 25 port [tcp/smtp] succeeded!

The port range was specified to limit the search to ports 20 - 30.

Alternatively, it might be useful to know which server software is running, and which versions. This information is often contained within the greeting banners. In order to retrieve these, it is necessary to first make a connection, and then break the connection when the banner has been retrieved. This can be accomplished by specifying a small timeout with the -w flag, or perhaps by issuing a "QUIT" command to the server:

$ echo "QUIT" | nc host.example.com 20-30
SSH-1.99-OpenSSH_3.6.1p2
Protocol mismatch.
220 host.example.com IMS SMTP Receiver Version 0.84 Ready

Solaris: using nc to transfer file

DATA TRANSFER

The example in the previous section can be expanded to build a basic data transfermodel. Any information input into one end of the connection will be output to the other end,and input and output can be easily captured in order to emulate file transfer.
 
     Start by using nc to listen on a specific port, with output captured into
     a file:

           $ nc -l 1234 > filename.out

     Using a second machine, connect to the listening nc process, feeding it
     the file which is to be transferred:

           $ nc host.example.com 1234 < filename.in

     After the file has been transferred, the connection will close automati-
     cally.

UNIX: How to print column nicely using printf

[user@hostfwnms1-oam tmp]# cat b.sh printf "%-26s %-19s %-8s %-8s %-s %-s\n" HOSTNAME IP PING SNMPWALK 0-ok 1-fail for i in `cat n...