<SOLVED> mounting from script not working

Forum rules
Before you post please read this

<SOLVED> mounting from script not working

Postby tadaensylvermane on Tue Jun 10, 2014 11:01 pm

Code: Select all
# variables #

BUOPT="rsync -auv --include-from=/media/data/.includes --exclude=/* /media/data/ $2 --delete"

##### begin script #####

databu() {
   if ! mountpoint -q $2 ; then
      mount $2 && $BUOPT
   else
      $BUOPT
   fi
}


The rsync variable works. That much is good. When I comment out the rsync and the else parts (to test the mount itself) it spams the terminal with
Code: Select all
Usage: mountpoint [-q] [-d] [-x] path

followed by what looks like a list of every single current mount point. What is wrong here?
Last edited by tadaensylvermane on Thu Jun 12, 2014 10:43 pm, edited 1 time in total.
tadaensylvermane
Level 2
Level 2
 
Posts: 71
Joined: Tue Jun 25, 2013 8:50 pm

Linux Mint is funded by ads and donations.
 

Re: mounting from script not working

Postby Habitual on Wed Jun 11, 2014 10:26 am

I use this often on mounts:
Code: Select all
#!/bin/bash
# Written by cirrhus9.com
# 06/10/2014
if $(cat /proc/mounts | grep <mount_name> > /dev/null) 
then
ionice -c 3 rsync -phavz --stats --log-file=/tmp/rsync.out <source> <destination> --delete
else
   echo "<mount_name> Backup Drive is NOT mounted"
   exit
fi
#EOF

adjust accordingly.
What's a landing but a take off in reverse?
My DorkBlog
shellshock.conf for fail2ban 0.8.10
User avatar
Habitual
Level 8
Level 8
 
Posts: 2182
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: mounting from script not working

Postby WharfRat on Wed Jun 11, 2014 5:57 pm

tadaensylvermane,

It looks like you're using the wrong positional parameter as that message will result from not including a path. Maybe it should be "$1" :?:
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4198
Joined: Thu Apr 07, 2011 8:15 pm

Re: mounting from script not working

Postby tadaensylvermane on Thu Jun 12, 2014 10:43 pm

WharfRat wrote:tadaensylvermane,

It looks like you're using the wrong positional parameter as that message will result from not including a path. Maybe it should be "$1" :?:



Now I feel a fool. Thank you much. Solved. To be clear these were being called with case, so first arg was the function to call. I figured the positional would have to be $2 as the first is the function call itself. :oops:

Finished script in question starting from this thread viewtopic.php?f=213&t=165975

Code: Select all
#!/bin/bash
#Tadaen Sylvermane
#Backups

##### begin script #####

databu() {
   if ! mountpoint -q $2 ; then
      mount $2 && rsync -auv --include-from=${1}.includes --exclude=/* $1 $2 --delete
   else
      rsync -auv --include-from=${1}.includes --exclude=/* $1 $2 --delete
   fi
}

cachebu() {
   if [ -d $2 ] ; then
      find $1 -iname "*.deb" -exec rsync -ru {} $2 --delete \;
   fi
}


case "$1" in
   data)
      databu /media/data/ /home/jason/.backups
      ;;
   cache)
      cachebu /var/cache/apt/archives /media/data/Debian/cache
      ;;
   *)
      echo "usage: $0 {data | cache}"
      exit 1
      ;;
esac

exit 0
tadaensylvermane
Level 2
Level 2
 
Posts: 71
Joined: Tue Jun 25, 2013 8:50 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests