Tuesday, May 1, 2012

HowTo: Restart UNIX System / Server

How do I restart UNIX server or workstation?

You can use the following procedure to restart a UNIX system.
Login as root user. If you are not root use, use su or sudo command as follows:
su -
OR
sudo -i
Once logged in as root, type the reboot command to reboot the system:
# reboot
You can also use the shutdown command as follows:
# shutdown -r now
If you are using Solaris UNIX, try the following command:
# shutdown -y -i6 -g0
Where,
  • -y : Do not prompt for any questions.
  • -i6 : Indicates init level 6 which is nothing but reboot.
  • -g0: Grace period, the default is 60 seconds. To reboot immediately set it to zero (0).

Shut Down a Solaris UNIX System

How do I shutdown a Solaris UNIX machine or server using command prompt?

You need to use the shutdown command as follows (you must login as root):
# shutdown -y -g0 -i S
The following command will scheduled a shutdown in 180 seconds and will display message "Memory upgrade, save all data " to all logged in members:
shutdown -i S -g 180 "***  Memory upgrade, save all data ***"
The shutdown command can be aborted before completing 180 seconds counter.

poweroff Command

You can also use the poweroff command its is equivalent init 5:
# poweroff
OR
# init 5

HowTo: UNIX Restart Apache Server

How do I restart Apache web server under UNIX operating systems using command line or over the ssh session?

You need to use the apachectl command to restart the Apache server. This will reread its configuration files, and reopens log files. Type the following command as root user (use su - to become root):
# apachectl -k restart
OR use sudo (if configured):
$ sudo apachectl -k restart
The above will immediately restart the Apache. However, in a production environment you may want to use graceful restart which will restart server after all current requests (or to exit immediately if they're not serving anything) are completed:
# apachectl -k graceful
OR use sudo (if configured):
$ sudo apachectl -k graceful
Finally, you can view the status of restart in a log file:
# tail -f /var/log/httpd/error_log
# tail -f /var/log/apache2/error.log

Linux: Find Out The Groups A User Is In

How do I find out group membership for each user? How do I find out which users are in a group called sales?

The groups command display the groups a user is in. In this example, find out the group membership for user vivek, enter:
 groups userName
groups vivek
Sample outputs:
vivek : vivek adm dialout cdrom plugdev lpadmin netdev admin sambashare libvirtd
User vivek is member all of the above groups. Find out all users belongs to the group called adm:
grep -w groupName /etc/group
grep -w adm /etc/group
Sample outputs:
adm:x:4:vivek,top,jerry

HowTo: Restart SSH Service under Linux / UNIX

How do I restart SSH service under Linux or UNIX operating systems?

The command to restart ssh are as follows (you must login as root user):

CentOS / RHEL / Fedora / Redhat Linux Restart SSH

# /etc/init.d/sshd restart
OR
# service sshd restart

Debian / Ubuntu Linux Restart SSH

# /etc/init.d/ssh restart
OR
# service ssh restart

FreeBSD Restart SSH

# /etc/rc.d/sshd restart

UNIX Restart SSH

# kill -HUP `cat /var/run/sshd.pid`
Please note that the location of /var/run/sshd.pid may change. So just search a bit through /var/run/ directory.

Monday, April 30, 2012

HowTo: Restart SSH Service under Linux / UNIX

How do I restart SSH service under Linux or UNIX operating systems?

The command to restart ssh are as follows (you must login as root user):

CentOS / RHEL / Fedora / Redhat Linux Restart SSH

# /etc/init.d/sshd restart
OR
# service sshd restart

Debian / Ubuntu Linux Restart SSH

# /etc/init.d/ssh restart
OR
# service ssh restart

FreeBSD Restart SSH

# /etc/rc.d/sshd restart

UNIX Restart SSH

# kill -HUP `cat /var/run/sshd.pid`
Please note that the location of /var/run/sshd.pid may change. So just search a bit through /var/run/ directory.

KSH For Loop Array: Iterate Through Array Values

How do I use ksh for loop to iterate thought array values under UNIX / Linux / BSD operating systems?

You can define array as follows:
set -A arrayName value1 value2 value3
For example, create an array called characters with three values as follows:
set -A characters Mugen Jin Fuu
To print first value, enter:
echo ${characters[0]}
To print 3rd and last value, enter:
echo ${characters[2]}
To print all values, enter:
echo ${characters[@]}
To count number of items in an array called characters, enter:
echo ${#characters[@]}
You can use for loop as follows to iterate through all values:
for i in ${characters[@]}; do echo "Samurai Champloo character - $i"; done
Sample outputs:
Samurai Champloo character - Mugen
Samurai Champloo character - Jin
Samurai Champloo character - Fuu
You can add two more items as follows to exiting array:
characters[3]="Sunflower-Samurai"
characters[4]="Detective-Manzo"

Sample Shell Script

#!/bin/ksh
# set array called nameservers
set -A nameservers 192.168.1.1 192.168.1.5 202.54.1.5
 
# print all name servers
for i in ${nameservers[@]
do
echo $i
done