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 # 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 nfs.rc in ~/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...
- RSS feed or Weekly email newsletter
- 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |