A simple shell script wrapper to start / stop / restart NFSv4 service on CentOS / RHEL v.6.x server in a particular order. This script also demonstrates how to use the ln command to create soft links to the same script and take a different action as per $0.
#!/bin/bash # A simple shell script wrapper start / stop / restart nfsv4 services on CentOS / RHEL # based systems. # Tested on: RHEL / CentOS but can be ported to Debian or other distros. # ---------------------------------------------------------------------------- # Author: nixCraft <http://www.cyberciti.biz> # Copyright: 2009 nixCraft under GNU GPL v2.0+ # ---------------------------------------------------------------------------- # Last updated: 20/Mar/2013 - Added support for RHEL 6.x # ---------------------------------------------------------------------------- # Who am I? _me=${0##*/} ## RHEL/CentOS init.d script names _server="/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock /etc/init.d/nfs" _client="/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock" _action="$1" ## Run either server or client script with the following action: # stop|start|restart|status ## runme(){ local i="$1" local a="$2" for t in $i do $t $a done } usage(){ echo "$_me start|stop|restart|reload|status"; exit 0 } [ $# -eq 0 ] && usage ## Main logic case $_me in nfs.server) runme "$_server" "$_action" ;; nfs.client) runme "$_client" "$_action" ;; *) usage esac
How do I use this script?
Download and install the script as follows:
wget http://bash.cyberciti.biz/dl/605.sh.zip
unzip 605.sh.zip
mv 605.sh nfs.rc
mkdir ~/bin/
mv nfs.rc ~/bin/
cd ~/bin/
chmod +x nfs.rc
ln -s nfs.rc nfs.server
ln -s nfs.rc nfs.client
To start / stop / restart nfsv4 server services in a single go:
# ~/bin/nfs.server stop
# ~/bin/nfs.server status
# ~/bin/nfs.server start
# ~/bin/nfs.server restart
To start / stop / restart nfsv4 clients in a single go, enter:
# ~/bin/nfs.client stop
# ~/bin/nfs.client start
# ~/bin/nfs.client restart
# ~/bin/nfs.client status
Sample outputs:
rpcbind (pid 2379) is running... rpc.idmapd (pid 7410) is running... rpc.statd (pid 2397) is running...
Click here to subscribe via email.
- Download Script
- Email this to a friend
- Rss Feed
- Last Updated: 03/19/13





