LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2013, 08:41 PM   #1
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Rep: Reputation: Disabled
Script


I made a script for mounting but what how would I post that it has mounted sucessfully in the script. I want to echo "Mounted all sucessfully" and "One or more didn't not mount sucessfully. It's pulls from my fstab. Any help would be great! Thanks!
 
Old 02-27-2013, 09:49 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,

the mount command should return with a non zero status if there were errors. Eg.

Code:
#!/bin/sh
mount -t ext4 /dev/foo /amountpoint
if [ "$?" = "0" ] ; then
  echo "Sucessfully mounted /dev/foo at /amountpoint"
fi
If this doesn't help, perhaps you could post your script and explain in more detail what you are trying to do.

Evo2.
 
1 members found this post helpful.
Old 02-28-2013, 02:09 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Generally difficult to assist without seeing the code as you may have loops and or read statements to deal with that could cause output to not display.
 
Old 02-28-2013, 03:16 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Indeed, better to see what you've tried so far. Anyway, using a loop you may want something like this:
Code:
while read device mount_point
do
  mount $device $mount_point || NO_MOUNT=1
done < list_of_devices_and_mount_points

[[ -z $NO_MOUNT ]] && echo Mounted all successfully || echo One or more didn't mount successfully
 
Old 02-28-2013, 09:11 PM   #5
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Original Poster
Rep: Reputation: Disabled
Script

The script is:

Code:
#!/usr/bin/expect

spawn su -
expect "Password: "
send "Password\r"
send "mount -a\r"
interact
It's a small script but obviously to do all the mounting it needs to be in root. After mount -a, if it successfully mounts without an error I want to echo "Mounted Sucessfully" if didn't mount all, I want it to echo "One or more have not sucessfully mounted". Thank you in advance for your help.

Last edited by poseidonsurf; 02-28-2013 at 10:08 PM. Reason: Expanded.
 
Old 02-28-2013, 11:45 PM   #6
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,

it is *REALLY* bad idea to use expect like that to provide the root password.

Anyway as we've already mentioned mount will exit with 0 status if there were no problems, and non zero otherwise. We have also already provided example code for this.

Evo2.
 
Old 03-01-2013, 01:52 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Why on earth are you doing such a thing?
If it's in your fstab just:

sudo mount /blah

It's like using a drill as a food mixer when you have an electric whisk in the cupboard.
 
2 members found this post helpful.
Old 03-01-2013, 07:22 AM   #8
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Original Poster
Rep: Reputation: Disabled
Thank you everyone for you quick replies. Evo2 - I thought I needed root to mount all drives? Maybe not. I will see. Is there a way to put a count down before the screen exits?
 
Old 03-03-2013, 09:08 PM   #9
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,

Quote:
Originally Posted by poseidonsurf View Post
I thought I needed root to mount all drives? Maybe not. I will see.
You don't need root to mount drives that have the flag "user" in /etc/fstab. Also any drive that does not have the "noauto" flag will be mounted automatically at boot (and whenever "mount -a" is run. Have a look at the mount and fstab man pages.

Quote:
Is there a way to put a count down before the screen exits?
Sorry, I don't understand the question.

Evo2.
 
Old 03-04-2013, 10:37 PM   #10
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Original Poster
Rep: Reputation: Disabled
It states only root can perform mounts.
 
Old 05-13-2014, 05:10 PM   #11
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,
Quote:
Originally Posted by poseidonsurf View Post
It states only root can perform mounts.
What does?

Evo2.
 
Old 05-14-2014, 06:42 AM   #12
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Original Poster
Rep: Reputation: Disabled
I figured it out. Thank you though.
 
Old 05-14-2014, 09:15 AM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Would you like to share with the rest of the class so others can learn from what you found?
 
Old 07-18-2014, 08:01 PM   #14
poseidonsurf
Member
 
Registered: Feb 2013
Distribution: Slackware, Debian
Posts: 38

Original Poster
Rep: Reputation: Disabled
I used sudo instead
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 09:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 01:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 06:00 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 01:27 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:10 PM.

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