1827757 Members
2958 Online
109969 Solutions
New Discussion

Re: Question of syntax

 
Andrew Kaplan
Super Advisor

Question of syntax

Hi there --

The code listed below is an excerpt from a script that I am writing. The goal is to verify that a directory on a remote server is available to the local system. If that is not the case, a log file is written, and all filesystems that were previous unmounted, are remounted on the local system.

###############################################
# Unmount all NFS mounts prior to the archive process.
umount -a -t nfs

# Mount the remote directory (NFS) prior to running the make_net_recovery script.
# Make sure there is a folder located in the /mnt directory. If it is
# not already there, create one.
mount :/ /mnt/

# Verify the remote directory (NFS) is available. This directory is needed
# as it is the destination for the iso images. If it is not available, stop
# here, and write the results to a log file.
df |grep > /dev/null
RC=$?
echo $RC

if [ ${RC} -eq 0 ]
then
echo successful
else
echo not successful >> /tmp/make_net_backup.log && mount -a
exit
fi
###############################################

Is the syntax shown above correct? Thanks.
A Journey In The Quest Of Knowledge
2 REPLIES 2
Steven Schweda
Honored Contributor

Re: Question of syntax

> Is the syntax shown above correct?

Why not run the script, and get the opinion
of the shell, which is the only opinion which
matters?
Dennis Handly
Acclaimed Contributor

Re: Question of syntax

>Is the syntax shown above correct?

A real shell has the "-n" option to check.

Some comments:
df | grep > /dev/null

You can remove the redirection with:
df | grep -q

echo not successful >> /tmp/make_net_backup.log && mount -a

Any reason you are using "&&" here? Why would an error in writing to your log keep you from trying to mount?