-----Original Message----- From: Rajeev R. K.
Here you go.....
mount | grep -q home HOMESTATUS=$? mount | grep -q backup BACKUPSTATUS=$?
if [ $HOMESTATUS -eq 0 -a $BACKUPSTATUS -eq 0 ]; then echo "You got both man, do your thing..." exit 0; else echo "Error -- either home or backup missing -- Or is it BOTH !%$!!@#%!" exit 1; fi
Regards R. K. Rajeev
Thanks Rajeev and Binand for your tips. I noticed a '-a' option in the if statement so will this below work?
If [grep -q "/home" mtab -a grep -q "/backup" mtab ] then.........
Regards, Rony.
On 27 February 2013 23:40, gnulinuxist@gmail.com gnulinuxist@gmail.com wrote:
-----Original Message----- From: Rajeev R. K.
Here you go.....
mount | grep -q home HOMESTATUS=$? mount | grep -q backup BACKUPSTATUS=$?
if [ $HOMESTATUS -eq 0 -a $BACKUPSTATUS -eq 0 ]; then echo "You got both man, do your thing..." exit 0; else echo "Error -- either home or backup missing -- Or is it BOTH !%$!!@#%!" exit 1; fi
Regards R. K. Rajeev
Thanks Rajeev and Binand for your tips. I noticed a '-a' option in the if statement so will this below work?
If [grep -q "/home" mtab -a grep -q "/backup" mtab ] then.........
Doubtful, since the square brackets are little more than a shorthand for encapsulating the conditional and comparative expression syntax of the test command(check man test), and in this case, test would not know how to evaluate the expressions. In any case, my earlier point about having independent tests still stands from a usability standpoint.
Regards R. K. Rajeev
Regards, Rony.
Hi Rony, Rajeev,
On Thu, Feb 28, 2013 at 12:01 AM, Rajeev R. K. rajeevrk@gmail.com wrote:
On 27 February 2013 23:40, gnulinuxist@gmail.com gnulinuxist@gmail.com wrote:
Thanks Rajeev and Binand for your tips. I noticed a '-a' option in the if statement so will this below work?
If [grep -q "/home" mtab -a grep -q "/backup" mtab ] then.........
Doubtful, since the square brackets are little more than a shorthand for encapsulating the conditional and comparative expression syntax of the test command(check man test), and in this case, test would not know how to evaluate the expressions. In any case, my earlier point about having independent tests still stands from a usability standpoint.
You can omit the square brackets and use "-a" as: if grep -q /home /etc/mtab -a grep -q /backup /etc/mtab ; then ...
Furthermore, to avoid invalid matches such as "/home1" or "/export/home", you can use the "-w" option, if your version of grep supports it (GNU grep does).
However, I wouldn't recommend: if [ $( grep -cwE '/(home|backup)' /etc/mtab ) = 2 ]; then ... as some versions of Linux allow a file system to be mounted multiple times. So, we would get a false positive if /home is mounted twice, but /backup is not.
A method that's both concise and readable is: home_mounted=`grep -w /home /etc/mtab` backup_mounted=`grep -w /backup /etc/mtab` if [ "$home_mounted" -a "$backup_mounted" ] ; then ...
Regards, Osric Xavier Fernandes
PS: Great to have the mailing list back. Good job team!
Hi,
I know the question was answered, but ...
On Thursday 28 February 2013 01:18 AM, Osric Fernandes wrote:
Hi Rony, Rajeev, [...snip...]
A method that's both concise and readable is: home_mounted=`grep -w /home /etc/mtab` backup_mounted=`grep -w /backup /etc/mtab` if [ "$home_mounted" -a "$backup_mounted" ] ; then ...
Just FYI, a usual idiom for doing thing like this is simply:
grep -q "something" /some/where && \ grep -q "something else" /some/place/else && \ do_your_thing
with this you can chain as many pre-conditions as you want, and the benefit is, if any one of the commands before the final one fails, the rest of the commands are not executed. This isn't a huge win in the specific scenario being discussed, but can significantly impact some scripts.
cheers, -steve
Regards, Osric Xavier Fernandes
PS: Great to have the mailing list back. Good job team!