468x60 Ads

Friday, May 30, 2014

Searching for Files that have been modified within a specified time frame (using find command)


Searching for Files that have been modified within a specified time frame (using find command)

Find command is use for searching files that meet conditions you specify.

For more information about find command:


man page in Solaris 10:

 

find directory options

 

-atimen             True if the file  was  accessed  n  days ago.  The  access time of directories in

                         path is changed by find itself.

 

-ctime n            True if the file's status was changed  n days ago.

-mtime n            True if the file's data was  modified  n days ago.

 

The descriptions of -atime, -ctime, and -mtime use the  ter-minology n ``24-hour periods''. For example, a file accessed at 23:59 is selected by:

 

       example% find . -atime -1 -print

 

     at 00:01 the next day (less than 24 hours  later,  not  more than one day ago). The midnight boundary between days has no effect on the 24-hour calculation.

 

 

Eg:Find files in current directory that have been modified in last 24h time

  #find . -ctime -1 -type f

Wednesday, March 12, 2014

How to add telnet SSH warning/logging banner/message in solaris 10

We can add our system warning/logging banner/message by editing /etc/motd file. This message will appear once after we are logging in to system using Telnet/SSh/..etc. methord. (displayed after login)


# vi /etc/motd
"/etc/motd" 1 line, 57 characters
#########################################################################
#                   ----Sri Lanka XXXX PVT. LTD.----                 
# This system is for the use of authorized users only.             
# Individuals using this computer system without authority, or                     
# in excess of their authority, are subject to having all of                         
# activities on this system monitored and recorded by system personnel.
#########################################################################

Eg:

login as: dara
Using keyboard-interactive authentication.
Password:
Access denied
Using keyboard-interactive authentication.
Password:
Last login: Wed Mar 12 11:43:09 2014 from 172.16.0.6
#########################################################################
#                   ----Sri Lanka XXXX PVT. LTD.----                 
# This system is for the use of authorized users only.             
# Individuals using this computer system without authority, or                     
# in excess of their authority, are subject to having all of                         
# activities on this system monitored and recorded by system personnel.
#########################################################################
-bash-3.00$


For telnet we can place a banner to display while trying to access server by editing /etc/default/telnetd file.


# vi /etc/default/telnetd
"/etc/default/telnetd" [Read only] 20 lines, 652 characters
#ident  "@(#)telnetd.dfl        1.1     01/11/01 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#
# /etc/default/telnetd
#
# telnetd default settings processed via telnetd(1M).
#
# BANNER defines the connection banner which is displayed before the
# telnet login prompt, see telnetd(1M) for details.  The following
# commented line shows the default value.
#
#BANNER="\\r\\n\\r\\n`uname -s` `uname -r`\\r\\n\\r\\n"
#
#
# Suppress the telnet banner by supplying a null definition.
#
BANNER="**********************Warning************************\\r\\n\\r\\n uthorized uses only.All activity may be monitored and reported\\r\\n\\r\\n"


For SSH:



# vi /etc/ssh/sshd_config
.
.
.
# Banner to be printed before authentication starts.
Banner /etc/issue
.
.

.

Eg:
>telnet 172.16.0.4
**********************Warning************************

 uthorized uses only.All activity may be monitored and reported

login:

Friday, March 7, 2014

See default ports in solaris 10

# cat /etc/services
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident  "@(#)services   1.34    08/11/19 SMI"
#
# Network services, Internet style
#
tcpmux          1/tcp
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
daytime         13/tcp
daytime         13/udp
netstat         15/tcp
chargen         19/tcp          ttytst source
chargen         19/udp          ttytst source
ftp-data        20/tcp
ftp             21/tcp
ssh             22/tcp                          # Secure Shell
telnet          23/tcp
smtp            25/tcp          mail
time            37/tcp          timserver
time            37/udp          timserver
name            42/udp          nameserver
whois           43/tcp          nicname         # usually to sri-nic
domain          53/udp
domain          53/tcp
bootps          67/udp                          # BOOTP/DHCP server
bootpc          68/udp                          # BOOTP/DHCP client
kerberos        88/udp          kdc             # Kerberos V5 KDC
kerberos        88/tcp          kdc             # Kerberos V5 KDC
hostnames       101/tcp         hostname        # usually to sri-nic
pop2            109/tcp         pop-2           # Post Office Protocol - V2
pop3            110/tcp                         # Post Office Protocol - Version 3
sunrpc          111/udp         rpcbind
sunrpc          111/tcp         rpcbind
imap            143/tcp         imap2           # Internet Mail Access Protocol v2
ldap            389/tcp                         # Lightweight Directory Access Protocol
ldap            389/udp                         # Lightweight Directory Access Protocol
dhcpv6-client   546/udp         dhcpv6c         # DHCPv6 Client (RFC 3315)
dhcpv6-server   547/udp         dhcpv6s         # DHCPv6 Server (RFC 3315)
submission      587/tcp                         # Mail Message Submission
submission      587/udp                         #    see RFC 2476
ldaps           636/tcp                         # LDAP protocol over TLS/SSL (was sldap)
ldaps           636/udp                         # LDAP protocol over TLS/SSL (was sldap)
#
# Host specific functions
#
tftp            69/udp
rje             77/tcp
finger          79/tcp
link            87/tcp          ttylink
supdup          95/tcp
iso-tsap        102/tcp
x400            103/tcp                         # ISO Mail
x400-snd        104/tcp
csnet-ns        105/tcp
pop-2           109/tcp                         # Post Office
uucp-path       117/tcp
nntp            119/tcp         usenet          # Network News Transfer
ntp             123/tcp                         # Network Time Protocol
ntp             123/udp                         # Network Time Protocol
netbios-ns      137/tcp                         # NETBIOS Name Service
netbios-ns      137/udp                         # NETBIOS Name Service
netbios-dgm     138/tcp                         # NETBIOS Datagram Service
netbios-dgm     138/udp                         # NETBIOS Datagram Service
netbios-ssn     139/tcp                         # NETBIOS Session Service
netbios-ssn     139/udp                         # NETBIOS Session Service
NeWS            144/tcp         news            # Window System
slp             427/tcp         slp             # Service Location Protocol, V2
slp             427/udp         slp             # Service Location Protocol, V2
mobile-ip       434/udp         mobile-ip       # Mobile-IP
cvc_hostd       442/tcp                         # Network Console
ike             500/udp         ike             # Internet Key Exchange
uuidgen         697/tcp                         # UUID Generator
uuidgen         697/udp                         # UUID Generator
#
# UNIX specific services
#
# these are NOT officially assigned
#
exec            512/tcp
login           513/tcp
shell           514/tcp         cmd             # no passwords used
printer         515/tcp         spooler         # line printer spooler
courier         530/tcp         rpc             # experimental
uucp            540/tcp         uucpd           # uucp daemon
biff            512/udp         comsat
who             513/udp         whod
syslog          514/udp
talk            517/udp
route           520/udp         router routed
ripng           521/udp
klogin          543/tcp                         # Kerberos authenticated rlogin
kshell          544/tcp         cmd             # Kerberos authenticated remote shell
new-rwho        550/udp         new-who         # experimental
rmonitor        560/udp         rmonitord       # experimental
monitor         561/udp                         # experimental
pcserver        600/tcp                         # ECD Integrated PC board srvr
sun-dr          665/tcp                         # Remote Dynamic Reconfiguration
kerberos-adm    749/tcp                         # Kerberos V5 Administration
kerberos-adm    749/udp                         # Kerberos V5 Administration
kerberos-iv     750/udp                         # Kerberos V4 key server
krb5_prop       754/tcp                         # Kerberos V5 KDC propogation
ufsd            1008/tcp        ufsd            # UFS-aware server
ufsd            1008/udp        ufsd
cvc             1495/tcp                        # Network Console
ingreslock      1524/tcp
www-ldap-gw     1760/tcp                        # HTTP to LDAP gateway
www-ldap-gw     1760/udp                        # HTTP to LDAP gateway
listen          2766/tcp                        # System V listener port
nfsd            2049/udp        nfs             # NFS server daemon (clts)
nfsd            2049/tcp        nfs             # NFS server daemon (cots)
eklogin         2105/tcp                        # Kerberos encrypted rlogin
lockd           4045/udp                        # NFS lock daemon/manager
lockd           4045/tcp
ipsec-nat-t     4500/udp                        # IPsec NAT-Traversal
dtspc           6112/tcp                        # CDE subprocess control
fs              7100/tcp                        # Font server
#[swat] The swat service is added by the SUNWsmbar package.
#[swat] Removing the swat service manually while SUNWsmbar
#[swat] package is installed in the system can cause issues
#[swat] with smf(5) stability or with zones(5) installation.
swat            901/tcp                         # Samba Web Adm.Tool
apocd   38900/udp
snmpd           161/udp        snmp             # SMA snmp daemon
servicetag      6481/udp
servicetag      6481/tcp


You can just edit and restart 

Thursday, February 6, 2014

Setting Up NFS Services in Solaris10

Setting Up NFS Services for Sharing directories

Checking  nfs service status

# svcs -a |grep -i nfs
online         2012     svc:/network/nfs/status:default
online         2012     svc:/network/nfs/cbd:default
online         2012     svc:/network/nfs/mapid:default
online         2012     svc:/network/nfs/nlockmgr:default
online         2012     svc:/network/nfs/client:default
online         2012     svc:/network/nfs/rquota:default
online         12:17:33 svc:/network/nfs/server:default


Share any folder that you need share with nfs by editing /etc/dfs/dfstab file.

# cat /etc/dfs/dfstab

#       Place share(1M) commands here for automatic execution
#       on entering init state 3.
#
#       Issue the command 'svcadm enable network/nfs/server' to
#       run the NFS daemon processes and the share commands, after adding
#       the very first entry to this file.
#
#       share [-F fstype] [ -o options] [-d ""] [resource]
#       .e.g,
#       share  -F nfs  -o rw=engineering  -d "home dirs" /export/home2

/usr/sbin/share -F nfs -o rw -d "" /share

#


Disable the NFS service on the server.

# svcadm disable network/nfs/server


Enable the NFS service on the server.

# svcadm enable network/nfs/server



Select Different Versions of NFS on a Server

Edit the /etc/default/nfs file

NFS_SERVER_VERSMAX=value
NFS_SERVER_VERSMIN=value

Value :Provide the version number.


Mount NFS on the client.
# mount server-name:/share-point /local-dir


Check that the NFS services started on the NFS server 

# rpcinfo -s 172.16.0.4|egrep 'nfs|mountd'
    100005  3,2,1     ticots,ticotsord,tcp,ticlts,udp  mountd      superuser
    100003  4,3,2     tcp,udp                          nfs         1
    100227  3,2       tcp,udp                          nfs_acl     1

Check that the server's mountd is responding

# /usr/bin/rpcinfo -u 172.16.0.4 mountd
program 100005 version 1 ready and waiting
program 100005 version 2 ready and waiting
program 100005 version 3 ready and waiting

Verify that file system is shared as expected on the server

# showmount -e
export list for NTU-HQ-GLOBAL:
/share (everyone)


Some Troubleshoots:

#svcs -xv nfs/server
svc:/network/nfs/server:default (NFS server)
State: disabled since Tue Jan 12 12:19:22 2013
Reason: Disabled by an administrator.
   See: Sun Message ID: SMF-8000-06
   See: man -M /usr/share/man -s 1M nfsd
Impact: This service is not running.

It will say what is the problem of not starting the service, you can also go to that mention log file and observe error logs.

Nfs client mount RPC Error: Program not registered.

When trying to mount nfs partition from nfs client, its keep getting above message that saying
nfs client mount RPC Error: Program not registered.

# mount -t nfs 172.16.0.1:/usr/local/backup
mount: mount to NFS server 172.16.0.1' failed: RPC Error: Program not registered.
#

Solution

This is generally happens due to following reasons..
*not having any shared folders in server or
*not having necessary access rights to server or folder


NFS run in local Zones in solaris:

For this you have to enable nfs server in global Zone and for shearing you have to give local Zone path to mount point in nfstab

Eg: /usr/sbin/share -F nfs -o rw -d "" /Zones/EMS/root/share/backup

Wednesday, January 29, 2014

Display the number of files in a directory

Count the number of files in a directory

# ls -l | wc -l
   11484

#ls -1 targetdir | wc -l

Monday, January 27, 2014

Creating Persistent Routes in Solaris



Creating Persistent Routes in Solaris

Print the currently active routes:

# netstat -rn

Routing Table: IPv4
  Destination           Gateway           Flags  Ref     Use     Interface
-------------------- -------------------- ----- ----- ---------- ---------
default              172.16.0.254         UG        1 1650937522
10.0.0.0             172.16.0.12          UG        1   10206514
172.16.0.0           172.16.0.3           U         1    9528249 igb0:1
224.0.0.0            172.16.0.3           U         1          0 igb0:1
127.0.0.1            127.0.0.1            UH       19      26626 lo0:1

Add a route persistently:

# route -p add default ip-address

Eg:
# route -p add 192.168.10.0/24 172.16.0.10

-p             Make changes to the network route tables per-
                    sistent across system restarts. The operation
                    is applied  to  the  network  routing  tables
                    first  and, if successful, is then applied to
                    the list  of  saved  routes  used  at  system
                    startup.  In determining whether an operation
                    was successful, a failure to add a route that
                    already  exists  or to delete a route that is
                    not in the routing table is ignored. Particu-
                    lar  care  should be taken when using host or
                    network  names  in  persistent   routes,   as
                    network-based  name  resolution  services are
                    not available at the time routes are added at
                    startup.
          (Reference :Solaris man page)

For routes that are created by using this method, use following command
to display all of the static routes

 #route -p show 

Following examples creates an IPv4 route to the destination 192.168.10.0 and subnet  with the subnet  mask of 255.255.255.0(/24):

# route add 192.168.10.0/24 somegateway
       
# route add 192.168.10.0 -netmask 255.255.255.0 somegateway

# route add 192.168.10.0 somegateway 255.255.255.0

For IPv6, only “/” format is accepting for subnet. The following example creates an IPv6 route to the destination 35dd:: with netmask of 16 one-bits followed by 112 zero-bits.


# route add -inet6 35dd::/16 somegateway




Monday, January 6, 2014

Useful commands for checking/find Directories/Files in Solaris

Useful commands for checking/find Directories/Files in Solaris  

Display the Size of Directories, Sub-directories, and Files

du -summarize disk usage

(By default, file sizes are written in 512-byte units, rounded up to the next 512-byte unit.)
OPTIONS:
-a
Displays the size of each file and subdirectory, and the total number of blocks that are contained in the specified directory.
-s
Displays the total number of blocks that are contained in the specified directory.
# du -s /var/adm/
1198    /var/adm

-h
All sizes are scaled to a  human  readable  format,for  example,  34K, 244M, 5.7G, or 2.0T.
Displays the size of each directory in 1024–byte blocks.
# du -h /var/adm/
   1K   /var/adm/acct/fiscal
   1K   /var/adm/acct/nite
   1K   /var/adm/acct/sum
   4K   /var/adm/acct
   1K   /var/adm/streams
   1K   /var/adm/sm.bin
   1K   /var/adm/exacct
   1K   /var/adm/log
   1K   /var/adm/sa
 599K   /var/adm

-H
Displays the size of each directory in 1000–byte blocks.
# du -H /var/adm/
2       /var/adm/acct/fiscal
2       /var/adm/acct/nite
2       /var/adm/acct/sum
8       /var/adm/acct
2       /var/adm/streams
2       /var/adm/sm.bin
2       /var/adm/exacct
2       /var/adm/log
2       /var/adm/sa
1198    /var/adm



Using ls and find commands:

Changes the directory in to the place of files are locating

# ls [-lh] [-s]

-l
Displays a list of files and directories in long format , sizes in bytes.
# ls -l
total 115540
-rw-r--r--   1 root     root         233 May 21  2013 Cms2Serv.bak
-rw-rw-rw-   1 root     root         213 May 21  2013 Cms2Serv.ini
-rw-r--r--   1 root     root     56479733 Jan  7 10:26 EMdatabase0.sa
-rw-r--r--   1 root     root      639742 Jan  7 10:28 EMdetect_00.bin

-h
Scales file sizes and directory sizes into human readable format like Kbytes, Mbytes, Gbytes, or Tbytes when the file or directory size is larger than 1024 bytes.
# ls -l -h
total 115540
-rw-r--r--   1 root     root         233 May 21  2013 Cms2Serv.bak
-rw-rw-rw-   1 root     root         213 May 21  2013 Cms2Serv.ini
-rw-r--r--   1 root     root         54M Jan  7 10:26 EMdatabase0.sav
-rw-r--r--   1 root     root        625K Jan  7 10:28 EMdetect_00.bin

-S
Displays a list of the files and directories, showing the sizes in blocks.
# ls -s
total 115800
   2 Cms2Serv.bak     1280 EMdetect_00.bin    92 EMhist.sav         28 elementMan.cms

How to Find Large Files

If the characters or columns for the files are different, use following command to sort a list of files by block size, from largest to smallest.

# ls -l| sort +4rn | more

# ls -l | sort +4rn | more
-rw-r--r--   1 root     root     56660746 Jan  7 10:34 EMdatabase0.sav
-rw-r--r--   1 root     root      961820 Jan  7 09:58 EMhist.bak
-rw-r--r--   1 root     root      640113 Jan  7 10:33 EMdetect_01.bin
-rw-r--r--   1 root     root      639742 Jan  7 10:28 EMdetect_00.bin
drwxr-xr-x   2 root     root      233984 Jan  7 10:33 ipcfg
-rw-r--r--   1 root     root       51608 Jan  7 10:36 EMhist.sav
drwxr-xr-x   2 root     root       41472 Jan  7 09:48 ipinv

Note that this command sorts files in a list by the character that is in the fourth field, starting from the left.

If the characters or columns for the files are the same, use the following command to sort a list of files by block size, from largest to smallest.

# ls -s | sort -nr |more
Note that this command sorts files in a list, starting with the left most character.

Find Files That Exceed a Specified Size Limit

find directory -size +nnn
directory
Identifies the directory that you want to search.

-size +nnn
Nnn in 512-byte blocks. Files that exceed this size will list.

# find . -size +400 -print
./ipcfg
./ipcfg/ipdevcfg.bin
./EMdetect_01.bin
./EMdetect_00.bin
./EMhist.bak

./EMdatabase0.sav