Search code examples
bashmountdebian-busterfstab

sudo mount -t ntfs complains about not being in fstab only when done from bash


I have no problem with sudo mount -t ntfs4 server/drive /home/larry/folder but when I put this in a bash script it complains about not being in fstab. Can someone please help me here?

Here is the complete script. It allows me to mount or umount the drives. Some of the servers are Debian and some are Ubuntu. My client is Debian 10.

#!/bin/bash

function mountit()
{
    verb=$1
    from=$2
    to=$3
    echo "Input is $verb $from $to"
    if [ "$verb" == "mount" ]; then
    echo "sudo mount -t nfs4 $from $to"
    sudo /bin/mount -t nfs4 "$from $to" || true
    else
    echo "sudo umount $to"
    sudo /bin/umount "$to" || true
    fi
}

verb="mount"
if [ "$1" == "0" ]; then
verb="umount"
fi

if [ $1 == "umount" ]; then
verb="umount"
fi

echo "$verb drives"
echo "poseidon vhosts - webs"
mountit $verb "192.168.18.2:/var/www/vhosts" "/home/larry/webs"

echo "ramses data - data"
mountit $verb "192.168.18.8:/data" "/home/larry/data"

echo "ramses data1 - data1"
mountit $verb "192.168.18.8:/data1" "/home/larry/data1"

echo "ramses mydata - data2"
mountit $verb "192.168.18.8:/mydata" "/home/larry/data2"

echo "pavilion data1 - data3"
mountit $verb "192.168.18.66:/home/larry/data1" "/home/larry/data3"

echo "ramses data2 - data4"
mountit $verb "192.168.18.8:/data2" "/home/larry/data4"

echo "pavilion data3 - data5"
mountit $verb "192.168.18.66:/home/larry/data3" "/home/larry/data5"

Solution

  • Replace

    sudo /bin/mount -t nfs4 "$from $to"
    

    with

    sudo /bin/mount -t nfs4 "$from" "$to"