If you transferring any script file, plain files or text files between windows and SunOS Server and the file have ^M or nonwished characters you can resolve this issue following the next process:
SUPRESSING BLANK LINES
To suppress the blank lines
in a text file:
sed '/^$/d'
awk 'NF>0'
TERMINAL RESET
To reset your terminal after
accidently opening a binary
file you can use the
following command:
# tput sgr0
This is supported on Solaris.
CLEANUP DOS FILES
If you deal with DOS files and the "^M" character
always appears at the end of the line, here are
two ways to get rid of them.
If you edit the DOS text file with the "vi"
editor in UNIX, use the following from the
"vi" command line:
:%s/^V^M//g
From a Unix shell use the command:
% sed 's/^V^M//g' foo > foo.new
NOTE: ^V is control V and ^M is control M or Enter
JUST THE DIRECTORIES
It useful to be able to list all directories in
the current directory without any of the files.
ls -l | grep "^d"
KILL A USER, IN THE UNIX SENSE
DISCLAIMER:If you so choose to it is at your own discretion and you
are doing it at your own risk.
To kill all the processes associated with a particular user
simply:
# kill -9 `ps -aef | grep USER_LOGIN |awk '{ print $2 }'`
If you want to be a nice admin, tell him first.
KEEP THE USERS OFF WITH NOLOGIN
There is a way to disable any new login attempts into a
system. This can be achieved by simply creating a file
called /etc/nologin.
It can have a null file size or a message can be
placed into the file informing the status of the
system. If a user attempts to login remotely, a
message will display with contents of the
/etc/nologin file, and then disconnect the user.
However, ftp connections are not affected by this, if
ftpd is running.
UMOUNT BUSY DEVICES
The "umount" command unmounts a currently
mounted filesystem, which can be specified either
as a mounted-on directory or a filesystem.
If a mount point is busy, there are a couple
things to try:
# fuser -ck /File_System
# umount /File_System
PROTCOLS WITH NETSTAT
Use the command:
% netstat -an
It will show you what ports
are in use on the local and
foreign machines as well as
the protocol running over that
port for that connection and
IP address information. It
also displays the state of
the socket being used.
Using the above tip user can
identify the port to which he
wants to send data is busy
or free.
EFFICIENT COMMANDS
In anytime I see someone code
inefficiently. Here are three of the
most common mistakes, followed by a
better way to do the same thing.
Bad: cat somefile | grep something
Better: grep something somefile
Why: You're running one program (grep) instead of two (cat and grep).
Bad: ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why: You're running two commands (grep) instead of three (ps
and two greps).
Bad: cat /dev/null > somefile
Better: > somefile
Why: You're running a command (cat) with I/O redirection,
instead of just redirection.
Although the bad way will have the
same result, the good way is far
faster. This may seem trivial, but
the benefits will really show when
dealing with large files or loops.
BASH HOTKEYS
Bash provides many hot keys to ease use. Like
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands so that you don't
have to repeat long command.
ctrl-u -- clears the typing before the hotkey.
ctrl-a -- takes you to the begining of the command you are currently typing.
ctrl-e -- takes you to the end of the command you are currently typing in.
esc-b -- takes you back by one word while typing a command.
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-h -- deletes one letter at a time from the command you are typing in.
ctrl-z -- puts the currently running process in background, the process
can be brought back to run state by using fg command.
esc-p -- like ctrl-r lets you search through the previously given commands.
esc-. -- gives the last command you typed.
SORTING BY IP ADDRESS
If you ever need to sort a file by IP
address, this little command line will
serve you well:
# sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n
It will correctly sort IP addresses from
the first octet numerically, then each
following octet.
1.- Open the file using vi editor vi file.txt
2.- type the next command [space] :%!col -bx [enter]
3.- and close and save file.txt file
The issue has been resolved.!!
By Jacosta
You can change the ownership of all files owned by
a specific user to a different specific user by
simply running ...
find /export/home -user
Obviously you would place the current owner/new owner in place of the
<> listed in the command above ...
Example:
/usr/local/bin/top -o size -d1 28 >> File.out
-d1 Parameter capture 1 seg of activity.
28 Parameter number show only 28 lines of process.
How can I determine/identify what Host Bus Adapter (HBA) is installed in a Solaris server?
The prtpicl command outputs information to accurately determine the make and model of an HBA.
The subsystem-ID value determines the model of HBA. Reference this chart to determine the model of HBA: Review
On a Solaris system, ever want
to know how many disks are attached
but do not have root access?
% ls -al /dev/dsk/*s2 | grep -v c0t6
However you won't know the
size of the disk space?
Information provided by the Sans Institute:
http://www.sans.org
The ten most commonly exploited UNIX vulnerabilities?
Poor system administration practices
Reusable/poor passwords
Flawed SUID programs (e.g., rdist, binmail)
HTTP servers and CGI application vulnerabilities
Default "+" entries in the /etc/hosts.equiv file
NFS/NIS vulverabilities sendmail program bugs
Buffer overruns (e.g., gets(), syslog())
SUID shell scripts
Format time YYMMDDHHMM
# touch -c -t 0812141519 New.txt
Example:
# ssh USER@SERVER_REMOTE "tar -cvf - /opt/data/" | tar -xvf -
Send data to remote hosts
# tar cvf - data | ssh USER@SERVER_REMOTE "(cd /opt/; tar xvf -)"
PS1="$LOGNAME@`hostname` $ " export PS1
export HOST="`id |cut -d '(' -f2|cut -d ')' -f1' '`@`uname -n` "
export PS1='$HOST# '
You can check if and what version of recommended patches is installed with:
cat /var/sadm/install_data/Solaris*log |grep "^\*\*\* Install"
# cut -d: -f7 /etc/passwd | sort -u | sed "/^$/d" > /etc/shells
Edit file /etc/mail/sendmail.cf
Add in the PrivacyOptions variable with the next options flags
PrivacyOptions=authwarnings,needmailhelo, needexpnhelo, novrfy, noexpn
# vi /etc/default/passwd
WAXWEEKS=13
MINWEEKS=1
WARNWEEKS=1
PASSLENGTH=8
HISTORY=6
MINNONALPHA=2
MAXREPEATS=2
# awk -F: '$3 == 0 {print $1}' /etc/passwd
You can check if and what version of recommended patches is installed with:
# cat /var/sadm/install_data/Solaris*log |grep "^\*\*\* Install"
for i in daemon bin sys adm lp listen nobody noaccess nobody4
do
usermod -c "$i" $i
usermod -s /bin/false $i
done
CHECK ACCOUNT USER'S WITHOUT PASSWORD
# logins -p
# /usr/lib/sendmail -q -v and press Return.
Administering Data-Links in Exclusive-IP Non-Global Zones
Aplica a partir de version Solaris 10 8/07: Es necesario configurar esta propiedad sólo si la zona es una zona de IP exclusiva. Consulte Solaris 10 8/07: zonas no globales de IP exclusiva y Cómo configurar la zona.
http://docs.sun.com/app/docs/doc/820-2317/6ndu7jbp6?l=es&a=view"
http://docs.sun.com/app/docs/doc/820-2317/geprv?l=es&a=view
zonecfg:my-zone> set ip-type=exclusive
zonecfg:my-zone> add net
zonecfg:my-zone:net> set physical=nxge5
zonecfg:my-zone:net> end
root # zlogin ZONE ifconfig nxge5 plumb
root # zlogin ZONE ifconfig nxge5 10.0.100.145 netmask 255.255.255.0 broadcast + up
Ver status de la interface
root # dladm show-link
Removing "Drive Not Available" from Solaris
These are steps I followed to remove the LUNS which were unmasked from the system.
Removing the Unused/Unmasked LUNS from Solaris.
1. First Step is identifying the
2. Remove them from Volume Manager. In my case, they are veritas. so I used vxdisk rm
3. look at the cfgadm -al o/p to find the disks which are failing. they are failing because they are unmasked from this system and still OS sees them.
c3::50060482d53135b8,84 disk connected configured failing
c3::50060482d53135b8,86 disk connected configured failing
c3::50060482d53135b8,87 disk connected configured failing
3. luxadm -e offline /dev/rdsk/
4. cfgadm -o unusable_FCP_dev -c unconfigure c3::50060482d53135b8
# This will remove all unusable LUNS from system for particular controller and target id. don't worry there might be some
working devices on that target. This command won't affect them. they'll be in working state only.
5. clean the device files using devfsadm -Cv
6. You should be clear now in both format and cfgadm -al.
PCP is a script that can help you quickly find Processes (PIDs)
having particular TCP Port(s) open, TCP ports open by specific PIDs
or even list all the TCP Ports open by all PIDs running on your system.
PIDs for TCP Port
Run PCP with "-p" option to show the PIDs of processes having a
TCP port (say Port 22)
Example:
test@mx3 # ksh "pcp.ksh" -p 22
PID Process Name and Port
_________________________________________________________
26308 sshd 22
sockname: AF_INET 10.0.0.7 port: 22
sockname: AF_INET 10.0.0.7 port: 22
sockname: AF_INET 10.0.0.7 port: 22
_________________________________________________________
TCP Ports open by PIDs
Run PCP with "-P" option to show the TCP ports open by specific PID
PIDs for all open TCP Ports
Use the "-a" option to list all TCP ports open with all the PIDs
Many thanks for this Script Sam Nelson and Daniel Trinkle trinkle
Particionamiento de Disco.
Copiar particionamiento a nuevo disco C4T1D0 en un solo paso.
# prtvtoc /dev/rdsk/c4t2d0s2 | fmthard -s - /dev/rdsk/c4t1d0s2
Ver Servidores que sincronizan con NTP Server
# xntpdc -c monlist
MOVING FILES WITH CPIO
If you have a multitude of
files to move from one
directory or filesystem to
another, here's a one liner:
# find /old_directory -depth | cpio -pdmv /new_directory
This will move all of the
files under the specified
old_directory to the
new_directory, keeping the
same ownership, permissions,
and directory structure.
Automate transfers between two servers with sftp?
Create one file and then use that as input for the sftp command:
test01@ # vi commands_sftp.txt
cd uploads
put *.gz
exit
Connect to the remote machine and transfer the required file:
# sftp test01@remote_server < comandos_sftp.txt
How to use vxdump and vxrestore
# vxdump 0f - /respaldo | ( cd /respaldos2/fs_respaldo_am; vxrestore xf - )
List all tasks currently running on the system, use the following command: vxtask list
Example: # vxresize -g rootdg jetform +4g disk01 disk02
# vxtask list
TASKID PTID TYPE/STATE PCT PROGRESS
168 RDWRBACK/R 94.46% 18874368/27262976/26798080 RESYNC jetform
#
OpenSSH SFTP chroot()
only accounts that need access sftp
OpenSSH 4.8p1 minimal version supported
I made the following changes to /etc/ssh/sshd_config file:
#Subsystem sftp /usr/local/libexec/sftp-server
Subsystem sftp internal-sftp
Match user "user_transfer"
ChrootDirectory /export/home
# perl -i~ -pe 'y/\n//d' file.txt
# sed -n '1h;2,$H;${g;s/\n/,/g;s///g;p}' file.txt1. En Zona Global ubicar el path de la imagen ISO y montarla.
# /usr/sbin/lofiadm -a /opt/netbackup/NBU7.1_CLIENTES.iso /dev/lofi/1
# mount -F hsfs -o ro /dev/lofi/1 /mnt
2. Crear punto de montaje en Zona.
# mkdir -p /export/zones/foij-2/root/mediaNB
3. Montar en Zona
# mount -F lofs /mnt /export/zones/foij-2/root/mediaNB
4. Verificamos en la Zona el FS montado de la ISO.
# zlogin foij-2
foij-2 # df -h /mediaNB
Filesystem size used avail capacity Mounted on
/mediaNB 3.2G 3.2G 0K 100% /mediaNB
foij-2 #
root # du -kd / | sort +n
root # ps -ef -o pid,user,osz,args | sort +2n
La llave publica y privada id_rsa fue generada en SO UNIX/Linux, sin una passphrase.
Para poder usarla con Putty en Windows es necesario importar la llave privada con PuttyGen y guardarla como .ppk.
En putty:
Click en Conversions => Import Key
Click en Save Private Key y Yes para salvar sin una passphrase.
Resguardar la nueva key.ppk en una directorio seguro para evitar que sea eliminada.
Ir a Putty en Connection => SSH => Auth y agregar en Private Key file for authentication.
Validar conectividad con llave privada.
login as: connect01 This computing system is a company owned asset and provided for the exclusive use of authorized
personnel for business purposes. All information and data created, accessed, processed, or stored
using this system (including personal information) are subject to monitoring, auditing, or review to
the extent permitted by applicable law. Unauthorized use or abuse of this system may lead to
corrective action including termination of employment, civil and/or criminal penalties. Authenticating with public key "imported-openssh-key"
root@ # cd /var/adm/ root@ # ls -l wtmpx -rw-r--r-- 1 adm adm 1539641784 Apr 15 18:02 wtmpx root@ # /usr/lib/acct/fwtmp < /var/adm/wtmpx > /var/adm/wtmpx.`date +%Y%m%d` root@ # ls -l | grep wtmpx -rw-r--r-- 1 adm adm 1539693492 Apr 15 18:09 wtmpx -rw-r--r-- 1 root other 355949528 Apr 15 18:09 wtmpx.20150415 root@ # > /var/adm/wtmpx root@ # ls -l /var/adm/wtmpx -rw-r--r-- 1 adm adm 372 Apr 15 18:11 /var/adm/wtmpx root@ # gzip wtmpx.20150415 root@ # ls -l | grep wtmpx -rw-r--r-- 1 adm adm 10044 Apr 15 18:12 wtmpx -rw-r--r-- 1 root other 42045437 Apr 15 18:09 wtmpx.20150415.gz root@ #
root@ # echo ::memstat | mdb -k Page Summary Pages MB %Tot ------------ ---------------- ---------------- ---- Kernel 1577711 12325 9% ZFS File Data 1042587 8145 6% Anon 4504046 35187 27% Exec and libs 184297 1439 1% Page cache 949084 7414 6% Free (cachelist) 2038059 15922 12% Free (freelist) 6350360 49612 38% Total 16646144 130048 root@ #
* For certain classes of bug exploits
set noexec_user_stack = 1
* Log attempted exploits
set noexec_user_stack_log = 1
* File Descriptor parameter set for SAP
set rlim_fd_cur=2048
set rlim_fd_max=2048
* ZFS arch cache to 128G RAM
set zfs:zfs_arc_max=4294967296
KILL A USER, IN THE UNIX SENSE
DISCLAIMER:If you so choose to it is at your own discretion and you
are doing it at your own risk.
To kill all the processes associated with a particular user
simply:
# kill -9 `ps -aef | grep USER_LOGIN |awk '{ print $2 }'`
If you want to be a nice admin, tell him first.