Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a network attached storage (NAS) at home where I store pretty much all my media stuff (songs, videos, etc). I would like to mount it to a local directory in my notebook automatically every time I login at home so before mounting it I need to do a ping to see if it is answering (which means I'm home).

I already have the script to mount it (see below) but I have two questions:

1) How to use the answer from ping in order to see if its answering? I believe I have to use grep together with the ping command, but since I'm a new *nix user I'm not very fluent with it yet.

2) Where is the best place to put this script?

The mount command I have is this:

sudo mount -t cifs //myIpAddress/remoteDir /media/MyLibrary -o username=myUsername,password=myPassword,domain=myDomain,iocharset=utf8,file_mode=0777,dir_mode=0777

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

No need for grep or anything like that, just do this:

ping -c 4 foo && sudo mount ...

This basically uses the fact that ping returns true if the ping works, the -c limits it to 4 pings before returning. You can also do something if ping fails like this:

ping -c 4 foo || echo "FAILED!"

The other thing to consider is why you're mounting on login and not in your fstab, there are some good guides to mounting smb file storage online:

https://help.ubuntu.com/community/Samba/SambaClientGuide

http://www.mattvanstone.com/2006/06/automatically_mounting_smb_sha/

share|improve this answer
    
I thought that I needed to test to see if the server is online before mounting otherwise I would have problems. However, I just added the stuff in fstab and tested with wireless off or my NAS off and it worked pretty well. Thanks a lot! –  tucaz Nov 16 '10 at 1:35
    
If you re-edit your question to be less about smb, we can make this question and answer more useful for future readers. There is already I think questions for smb mounting. –  Martin Owens -doctormo- Nov 16 '10 at 3:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.