LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-19-2022, 05:27 AM   #16
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1

<Code removed>


I believe the issue is that "mount" isnt working. Running this as root works so the script isnt the issue. I know the username that runs the script.

Last edited by riahc3; 05-20-2022 at 03:05 AM.
 
Old 05-19-2022, 06:07 AM   #17
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,868

Rep: Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313
please use code tags that makes your script more readable
also would be nice to add some error handling to know which command was executed successfully.
And also there should be some error messages.
 
Old 05-19-2022, 06:14 AM   #18
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
please use code tags that makes your script more readable
also would be nice to add some error handling to know which command was executed successfully.
And also there should be some error messages.
25 lines of code....

Yeah that would be nice but I dont know how to do it.

To my surprise, I dont see any error message. It just gets to the last line
 
Old 05-19-2022, 06:15 AM   #19
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by riahc3 View Post
Code:
mount -t cifs //192.168.3.222/SHARENAME/FOLDER /mnt/FOLDER -o ro,username=USER,vers=1.0,password=PASS,nodev,uid=backup,file_mode=0444,dir_mode=0444
I believe the issue is that "mount" isnt working. Running this as root works so the script isnt the issue. I know the username that runs the script.
If you issue this mount command manually from the command line, does it work successfully?

Overall, what you can do are:
  • Add "set -vx" after your shebang line to enable debug output and that will give you additional information when you run the script.
  • You also can assign a variable to the output result of mount and echo that variable to ensure that mount succeeded.
  • Further as a script enhancement, you can either error out of the script with a log or continue, after checking the result of mount.
 
Old 05-19-2022, 06:18 AM   #20
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by rtmistler View Post
If you issue this mount command manually from the command line, does it work successfully?

Overall, what you can do are:
  • Add "set -vx" after your shebang line to enable debug output and that will give you additional information when you run the script.
  • You also can assign a variable to the output result of mount and echo that variable to ensure that mount succeeded.
  • Further as a script enhancement, you can either error out of the script with a log or continue, after checking the result of mount.
Yeah, thru CLI it works.

set -vx doesnt show my anything

How do I store the output result of mount and then echo that variable?

Would love to error out if mount doesnt work
 
Old 05-19-2022, 06:20 AM   #21
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
It just gives me the error of must be superuser to mount (what I suspected)
 
Old 05-19-2022, 06:21 AM   #22
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by riahc3 View Post
25 lines of code....

Yeah that would be nice but I dont know how to do it.

To my surprise, I dont see any error message. It just gets to the last line
I get it. Many is the time I wrote a quick 10 line script and by the time I was done it was larger.

Hopefully the diagnostic methods I've cited can get you further


I really do feel it would be worth adding a check to confirm mount succeeded:
Code:
VAR=mount ...
if [ $VAR .eq 0 ]; then (it succeeded)
 
Old 05-19-2022, 06:22 AM   #23
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by riahc3 View Post
It just gives me the error of must be superuser to mount (what I suspected)
Then the script is not user root as you felt it should be.

Suggest using the sudo command modifier for the mount command.
 
Old 05-19-2022, 06:25 AM   #24
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by rtmistler View Post
Then the script is not user root as you felt it should be.
Quote:
Originally Posted by riahc3
Running this as root works so the script isnt the issue. I know the username that runs the script.
Quote:
Originally Posted by rtmistler View Post
Suggest using the sudo command modifier for the mount command.
The user that runs the script isnt a superuser (cant be either for obvious security reasons)
 
Old 05-19-2022, 06:27 AM   #25
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,868

Rep: Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313
regarding code tags: I posted the link where is it explained. Would be nice to check that link
You need to learn a lot about linux and shell to understand how does it work.
For example set -xv itself will just switch on debugging output, but will not tell you anything about the error. Other commands will have more verbose output.
By default every system command will print an error message (including mount), so when you execute your script you have to see that error message.
There are ways to suppress error messages and handle errors, we don't know your environment and other settings, so we don't know how did you invoke this script.
 
Old 05-19-2022, 06:29 AM   #26
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
<Code removed>



Updated code

Last edited by riahc3; 05-20-2022 at 03:05 AM.
 
Old 05-19-2022, 06:31 AM   #27
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
when you execute your script you have to see that error message.
mount: /mnt/folder: must be superuser to use mount.
 
Old 05-19-2022, 06:39 AM   #28
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,868

Rep: Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313Reputation: 7313
Code:
res=mount -t cifs //192.168.3.222/SHARENAME/FOLDER /mnt/FOLDER -o ro,username=USER,vers=1.0,password=PASS,nodev,uid=backup,file_mode=0444,dir_mode=0444
if [ $res -ne 0 ]; then
This is wrong.
This should be:
Code:
mount -t cifs //192.168.3.222/SHARENAME/FOLDER /mnt/FOLDER -o ro,username=USER,vers=1.0,password=PASS,nodev,uid=backup,file_mode=0444,dir_mode=0444
res=$?
if [ $res -ne 0 ]; then
add sudo before mount, like this:
Code:
sudo mount -t cifs ....
res=$?
if you need
 
Old 05-19-2022, 06:42 AM   #29
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
This is wrong.
Quote:
Originally Posted by rtmistler View Post
I really do feel it would be worth adding a check to confirm mount succeeded:
Code:
VAR=mount ...
if [ $VAR .eq 0 ]; then (it succeeded)
Wasnt me.

Sure Ill add a sudo before the commmand, one min.

Last edited by riahc3; 05-19-2022 at 06:47 AM.
 
Old 05-19-2022, 06:44 AM   #30
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
"UNKNOWN: Mount did not work"

😂 Obviously, Im not surprised.
 
  


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
My LG Stylo 4 Has Been Hijacked by Remote Administrator and OS as Well as Kernel Have Been Modified LongDuckDong_69 Linux - Newbie 3 11-17-2019 03:41 PM
How to find a file that's modified more than 2 days ago but less than 5 days BudiKusasi Linux - Newbie 1 02-09-2018 07:25 PM
file has been modified in the last minute charleswilliams Linux - Server 1 08-25-2013 05:59 PM
[bash] Seeing if a file has been modified before/after a date w3stfa11 Programming 7 10-15-2006 06:02 PM
Get directory stats when a file has been modified? marri Programming 2 05-13-2004 08:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:43 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