Mount in script drives me crazy

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am using some backup script I found somewhere and modified it to my needs but I have problems with mounting shared folder. Here is problematic part of script:



#!/bin/bash
#
# Backup folder to storage

# Check if command is finished without errors

function startit()
command_output=$(eval $1)
output_value=$?
if [ $output_value != 0 ]; then
echo "Failure!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
exit -1
else
echo "Success!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
fi
return $output_value


# Parameters

SHARED="/folder/shared/"
MOUNTPOINT="//server.some.address/backup/SharedFiles/"
TARGET="/backup/shared/"
TIMES=`date '+%Y.%m.%d_%H'`
TIMESTART=`date '+%Y.%m.%d %H:%M'`
USERNAME="someusername"
PASS="somepass"

# BackupStart

echo "Backup is started" >> /var/log/backup/sharefiles/webserver_$TIMES.log
echo "Now is $TIMESTART" >> /var/log/backup/sharefiles/webserver_$TIMES.log

# Mount shared folder to server

echo "Mount Storage share" >> /var/log/backup/sharefiles/webserver_$TIMES.log
startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


Every time I start script it shows that mount is failed and I get error



mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


My first guess was that I messed something with variables so I set



startit "mount -t cifs -o user=someusername,password=somepass //server.some.address/backup/SharedFiles/ /backup/shared/"


instead



startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


And it works fine when I start script manually. BUT. Then I created cron job and error is back?!



What is even more weird on another server I have exact same script on exact same version of Linux (Centos 7) and it works flawlessly with same shared folder.



Does anyone have any idea?







share|improve this question















  • 3




    I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
    – Kusalananda
    Apr 27 at 8:34







  • 1




    Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
    – Giacomo Catenazzi
    Apr 27 at 8:44










  • I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
    – Ivica Vujovic
    Apr 27 at 13:11














up vote
0
down vote

favorite












I am using some backup script I found somewhere and modified it to my needs but I have problems with mounting shared folder. Here is problematic part of script:



#!/bin/bash
#
# Backup folder to storage

# Check if command is finished without errors

function startit()
command_output=$(eval $1)
output_value=$?
if [ $output_value != 0 ]; then
echo "Failure!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
exit -1
else
echo "Success!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
fi
return $output_value


# Parameters

SHARED="/folder/shared/"
MOUNTPOINT="//server.some.address/backup/SharedFiles/"
TARGET="/backup/shared/"
TIMES=`date '+%Y.%m.%d_%H'`
TIMESTART=`date '+%Y.%m.%d %H:%M'`
USERNAME="someusername"
PASS="somepass"

# BackupStart

echo "Backup is started" >> /var/log/backup/sharefiles/webserver_$TIMES.log
echo "Now is $TIMESTART" >> /var/log/backup/sharefiles/webserver_$TIMES.log

# Mount shared folder to server

echo "Mount Storage share" >> /var/log/backup/sharefiles/webserver_$TIMES.log
startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


Every time I start script it shows that mount is failed and I get error



mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


My first guess was that I messed something with variables so I set



startit "mount -t cifs -o user=someusername,password=somepass //server.some.address/backup/SharedFiles/ /backup/shared/"


instead



startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


And it works fine when I start script manually. BUT. Then I created cron job and error is back?!



What is even more weird on another server I have exact same script on exact same version of Linux (Centos 7) and it works flawlessly with same shared folder.



Does anyone have any idea?







share|improve this question















  • 3




    I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
    – Kusalananda
    Apr 27 at 8:34







  • 1




    Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
    – Giacomo Catenazzi
    Apr 27 at 8:44










  • I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
    – Ivica Vujovic
    Apr 27 at 13:11












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using some backup script I found somewhere and modified it to my needs but I have problems with mounting shared folder. Here is problematic part of script:



#!/bin/bash
#
# Backup folder to storage

# Check if command is finished without errors

function startit()
command_output=$(eval $1)
output_value=$?
if [ $output_value != 0 ]; then
echo "Failure!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
exit -1
else
echo "Success!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
fi
return $output_value


# Parameters

SHARED="/folder/shared/"
MOUNTPOINT="//server.some.address/backup/SharedFiles/"
TARGET="/backup/shared/"
TIMES=`date '+%Y.%m.%d_%H'`
TIMESTART=`date '+%Y.%m.%d %H:%M'`
USERNAME="someusername"
PASS="somepass"

# BackupStart

echo "Backup is started" >> /var/log/backup/sharefiles/webserver_$TIMES.log
echo "Now is $TIMESTART" >> /var/log/backup/sharefiles/webserver_$TIMES.log

# Mount shared folder to server

echo "Mount Storage share" >> /var/log/backup/sharefiles/webserver_$TIMES.log
startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


Every time I start script it shows that mount is failed and I get error



mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


My first guess was that I messed something with variables so I set



startit "mount -t cifs -o user=someusername,password=somepass //server.some.address/backup/SharedFiles/ /backup/shared/"


instead



startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


And it works fine when I start script manually. BUT. Then I created cron job and error is back?!



What is even more weird on another server I have exact same script on exact same version of Linux (Centos 7) and it works flawlessly with same shared folder.



Does anyone have any idea?







share|improve this question











I am using some backup script I found somewhere and modified it to my needs but I have problems with mounting shared folder. Here is problematic part of script:



#!/bin/bash
#
# Backup folder to storage

# Check if command is finished without errors

function startit()
command_output=$(eval $1)
output_value=$?
if [ $output_value != 0 ]; then
echo "Failure!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
exit -1
else
echo "Success!" >> /var/log/backup/sharefiles/webserver_$TIMES.log
fi
return $output_value


# Parameters

SHARED="/folder/shared/"
MOUNTPOINT="//server.some.address/backup/SharedFiles/"
TARGET="/backup/shared/"
TIMES=`date '+%Y.%m.%d_%H'`
TIMESTART=`date '+%Y.%m.%d %H:%M'`
USERNAME="someusername"
PASS="somepass"

# BackupStart

echo "Backup is started" >> /var/log/backup/sharefiles/webserver_$TIMES.log
echo "Now is $TIMESTART" >> /var/log/backup/sharefiles/webserver_$TIMES.log

# Mount shared folder to server

echo "Mount Storage share" >> /var/log/backup/sharefiles/webserver_$TIMES.log
startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


Every time I start script it shows that mount is failed and I get error



mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


My first guess was that I messed something with variables so I set



startit "mount -t cifs -o user=someusername,password=somepass //server.some.address/backup/SharedFiles/ /backup/shared/"


instead



startit "mount -t cifs -o user=$USERNAME,password=$PASS $MOUNTPOINT $TARGET"


And it works fine when I start script manually. BUT. Then I created cron job and error is back?!



What is even more weird on another server I have exact same script on exact same version of Linux (Centos 7) and it works flawlessly with same shared folder.



Does anyone have any idea?









share|improve this question










share|improve this question




share|improve this question









asked Apr 27 at 8:27









Ivica Vujovic

1




1







  • 3




    I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
    – Kusalananda
    Apr 27 at 8:34







  • 1




    Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
    – Giacomo Catenazzi
    Apr 27 at 8:44










  • I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
    – Ivica Vujovic
    Apr 27 at 13:11












  • 3




    I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
    – Kusalananda
    Apr 27 at 8:34







  • 1




    Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
    – Giacomo Catenazzi
    Apr 27 at 8:44










  • I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
    – Ivica Vujovic
    Apr 27 at 13:11







3




3




I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
– Kusalananda
Apr 27 at 8:34





I kinda wonder why you bother with a function at all. The function and the eval in it just adds complexity (and you are possibly getting the quoting wrong). Just do the mount in the main part of the script.
– Kusalananda
Apr 27 at 8:34





1




1




Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
– Giacomo Catenazzi
Apr 27 at 8:44




Do the target directory always exist? I think you should start debugging: add ` -x` on the first line. Check output. Print more. Shell is not forgiving about small errors.
– Giacomo Catenazzi
Apr 27 at 8:44












I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
– Ivica Vujovic
Apr 27 at 13:11




I have some delete job after mount and I just want to make sure everything is where it should be before that. I know it complicates things but didn't know how to simplify everything. Also target dir always exist and it is always the same one. Will try both suggestions. Hope it will help.
– Ivica Vujovic
Apr 27 at 13:11















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440362%2fmount-in-script-drives-me-crazy%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440362%2fmount-in-script-drives-me-crazy%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay