-1

This script should auto mount a file system on a Linux server.

testcheck=`df -h | awk '{print $6}' | grep "/test"`;

if [$tescheck -ne "/test"]
then
    mount /test
else
    echo "failed";
fi

I'm having a problem in the condition for making if statement true or false.

What am I doing wrong? Are there any alternatives that I can use?

Anthon
  • 79,293
jeff
  • 1
  • I would rather this be a comment, but apparently I need 50 rep to comment. You can use backticks instead of the $() convention, since the latter is BASH-specific and backticks will work across most or all posix shells. Also, is that your entire script? if it is, it will not work because you are not mounting anything in that command, but I'm assuming it's just a snippet from your script? But your question does state that it is your script, so I thought it best to check. – sevis127 Jan 29 '16 at 06:26
  • 1
    @sevis127: $(...) is in POSIX. – Michael Homer Jan 29 '16 at 09:09

1 Answers1

2
testcheck="$(df -h | awk '{print $6}' | grep "/test")"
if [ "$tescheck" != "/test" ]

update

I checked the shell syntax only and didn't check what you code does. To check whether something is mounted on /test you should do this:

if grep -E '^[^ ]+ /test ' /proc/mounts &>/dev/null; then
Hauke Laging
  • 90,279