LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   startup script (https://www.linuxquestions.org/questions/linux-general-1/startup-script-4175477806/)

JJJCR 09-19-2013 10:07 PM

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 :)

evo2 09-19-2013 11:37 PM

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.

JJJCR 09-20-2013 12:36 AM

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?

evo2 09-20-2013 12:47 AM

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.

JJJCR 09-20-2013 12:51 AM

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?

JJJCR 09-20-2013 01:30 AM

Quote:

Originally Posted by evo2 (Post 5031135)
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?

druuna 09-20-2013 02:09 AM

@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.

JJJCR 09-20-2013 03:37 AM

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.

druuna 09-20-2013 03:48 AM

Quote:

Originally Posted by JJJCR (Post 5031228)
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

JJJCR 09-20-2013 07:40 AM

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.. :)

JJJCR 09-20-2013 07:42 AM

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 &

Firerat 09-20-2013 08:05 AM

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

druuna 09-20-2013 08:06 AM

Quote:

Originally Posted by JJJCR (Post 5031326)
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 (Post 5031328)
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 &

JJJCR 09-20-2013 09:59 PM

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. ;)

Firerat 09-26-2013 08:06 PM

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


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