LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-19-2013, 10:07 PM   #1
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Smile startup script


hi guys, how i can set this command as a startup script?

mount -t cifs //192.168.1.17/Email -o username=admin,password=xxx111 /home/backup/Email

thanks for any input
 
Old 09-19-2013, 11:37 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

that can be done, but normally this is achieved by adding a line to your /etc/fstab, since during bootup all entries in the /etc/fstab that *don't* have the option "noauto" will be mounted.

The line you would want to add would be something like:
Code:
//192.168.1.117/Email /home/backup/Email cifs username=admin,password=xxx111 0 0
However, instead of putting the username and password in this file which is readable by everyone you might do better putting them in a root only readable file, for example /root/.cifs.conf. This file would contain:
Code:
username=admin
password=xxx111
and you would use the following line in your /etc/fstab
Code:
//192.168.1.117/Email /home/backup/Email cifs credentials=/root/.cifs.conf 0 0
HTH,

Evo2.
 
Old 09-20-2013, 12:36 AM   #3
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
hi evo2, for whatever reason I already have that on my fstab but it's not working.

that's why i'm thinking to have that as a startup script and execute the command.

thanks.

any ideas if I could set a shell script to do it?
 
Old 09-20-2013, 12:47 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you should not need to run a start up script. Instead you should try to debug why it is not being mounted. Have you checked your log files? Does, running it manually work? Eg with root privs:
Code:
mount /home/backup/Email
Evo2.
 
Old 09-20-2013, 12:51 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
i have this on my fstab:

//192.168.1.17/Email /home/backup/Email cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=admin,password=xxx111 0 0

it's not working any ideaS?
 
Old 09-20-2013, 01:30 AM   #6
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Lightbulb

Quote:
Originally Posted by evo2 View Post
Hi,

you should not need to run a start up script. Instead you should try to debug why it is not being mounted. Have you checked your log files? Does, running it manually work? Eg with root privs:
Code:
mount /home/backup/Email
Evo2.
hi evo2, yes running manually works fine. but it's not being done automatically by the fstab.

Thanks. any ideas?
 
Old 09-20-2013, 02:09 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@JJJCR: If you are able to run mount /home/backup/Email without any errors then the fstab entry itself is good. The mount command used from the command line doesn't have all the options that are needed, so the system will look in the fstab file and use what's there to complete the mount command.

Maybe the fstab order in which things are mounted isn't correct. / (and possibly /home) should be mounted before you try to mount the cifs mount.
 
Old 09-20-2013, 03:37 AM   #8
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
hi druuna, thanks for the reply. I can't really try it now even though I wanted to.
The server is on-line, users will jump on me, if I will reboot the server to try.

i'll find a good time to test it out.

The command I used on the fstab is this: //192.168.1.17/Email /home/backup/Email cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=admin,password=xxx111 0 0

is there anything i'm missing out on the line?

Thanks.
 
Old 09-20-2013, 03:48 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by JJJCR View Post
hi druuna, thanks for the reply. I can't really try it now even though I wanted to.
The server is on-line, users will jump on me, if I will reboot the server to try.

i'll find a good time to test it out.
Checking the fstab order doesn't interfere with a running server. Just look to make sure that the cifs line comes after the normal mounts (/, /home etc).

Quote:
The command I used on the fstab is this: //192.168.1.17/Email /home/backup/Email cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=admin,password=xxx111 0 0

is there anything i'm missing out on the line?
evo2 already answered that in post #2

BTW: You could use rc.local instead of fstab to mount the share. Add something like this: mount /home/backup/Email
 
Old 09-20-2013, 07:40 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
hi druuna, i will test out the rc.local it's a good idea.

Actually, the reason i want to reboot the server because I want to check whether the mounting will be done automatically.

Because sometimes there's a power shutdown on the building, I will just turn on the machine and a few days later I will realize that I have to mount some folders that is needed by the server.

So in order not to miss out this thing, I want it to be done automatically.

Thanks for all the ideas guys..
 
Old 09-20-2013, 07:42 AM   #11
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
I did some Googling, would this be right to put on rc.local?

sleep 70 && mount //192.168.1.17/Email /home/backup/Email cifs &
 
Old 09-20-2013, 08:05 AM   #12
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I assume the fstab entry doesn’t work as the network is not yet 'up'

I would be tempted to have noauto in the fstab, and in your rc.local
Code:
mount /home/backup/Email &
you have no need for sleep, that will just delay your boot by 70 seconds
I suppose 'backgrounding' the mount is ok ( added as red )

However, a cronjob with @reboot ( which means on boot ), might be better
setup correctly you will get a report if it goes wrong...


Having typed all that, fstab/mount should be smart enough to wait until networking is up
( based on it being type cifs )

But you could try adding _netdev to the options in fstab

As has already been pointed out by Evo2, you should be using credentials ( with 0600 perms )

try this..
Code:
//192.168.1.117/Email /home/backup/Email cifs _netdev,credentials=/root/.cifs.conf 0 0

Last edited by Firerat; 09-20-2013 at 08:08 AM.
 
Old 09-20-2013, 08:06 AM   #13
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by JJJCR View Post
Actually, the reason i want to reboot the server because I want to check whether the mounting will be done automatically.
Are you aware of mount's -a option?

mount -a will mount those entries that aren't mounted and do not have the noauto flag. Any new (or unmounted) entry in the fstab file can be mounted this way. However, mount -a doesn't look at the order of the entries.

The above won't replace a reboot, but it will give you a very good indication if the individual(!!) entries are processed correctly.

Quote:
Originally Posted by JJJCR View Post
I did some Googling, would this be right to put on rc.local?

sleep 70 && mount //192.168.1.17/Email /home/backup/Email cifs &
I'm not sure about the sleep part. rc.local is executed after all the rcX.d stuff is done. Maybe you need to wait a bit for things to settle down, maybe not. Experiment if at all possible.

A simpler mount command would do: mount /home/backup/Email &
I do assume that the cifs entry is present in your fstab file (and, as mentioned by you in post #6, mounting from the command line works).

If the cifs entry isn't present in fstab then you need the full blown mount command to be in rc.local, something like this:
Code:
mount -t cifs -o username=admin,password=xxx111 //192.168.1.17/Email /home/backup/Email &
Beware: rc.local is readable by normal users so I would go with evo2's suggestion and store the password and user in a root owned file (say /root/.cifs.conf) and use that instead for security reasons. This command would look like this:
Code:
mount -t cifs -o credentials=/root/.cifs.conf //192.168.1.17/Email /home/backup/Email &

Last edited by druuna; 09-20-2013 at 08:08 AM. Reason: Fixed typo.
 
Old 09-20-2013, 09:59 PM   #14
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
hi druuna, i'm not aware of the mount -a option. Thank you I will try it.

I will give it a shot.

@Evo2, thanks for pointing out the rc.local security that it will be visible to other users.

@Firerat, thanks for pointing out about the network. The mount option is pointing to the NAS.
I wasn't sure whether I turn on first the server, then after that I turn on the NAS.

Yup it could be that the NAS was not yet up when the email server was already up.

The suggesstion of druuna, about the mount -a option i will try that one.

Thank you guys for all your ideas and help. Keep you posted with the result.
 
Old 09-26-2013, 08:06 PM   #15
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Just read your last post,,
didn't realise something might be down ( the NAS )

You could have the @reboot cronjob test if the nas is available and mount,
If not send a WOL to it, sleep a little and test and hopefully mount
have it in an until loop
( until it succeeds or fails too many times )

properly written it can report failure
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Startup Script tuftystick Linux - Newbie 5 05-29-2010 11:12 PM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 09:40 PM
Startup script Larsza SUSE / openSUSE 7 10-21-2005 06:59 AM
startup script rockwell_001 Linux - General 4 04-21-2005 04:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration