LinuxQuestions.org
Help answer threads with 0 replies.
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 06-05-2019, 12:53 PM   #31
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206

Quote:
Originally Posted by riahc3 View Post
I dont know anything about shell scripting so I do not know what is wrong/right.
...
This is what I am asking. What errors are there?
So, in effect you have pasted whole cloth code presumably written by someone else, and you are asking others to understand it and debug it for you with little effort on your part and without gaining any understanding of it yourself?

That is not how LQ Programming forum should work. The forum is more about sharing knowledge than simply fixing code.

You have been given some excellent pointers by others, but you are going to have to understand how to use that knowledge, and how your script should work, and do your own debugging based on that new understanding.

Again, please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!

While others are always willing to go to some lenghts to help you learn and to resolve your problems, if you are waiting for others to simply do it for you, you may be asking in the wrong place.
 
Old 06-05-2019, 01:25 PM   #32
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by riahc3 View Post
Then I do not understand your posts. Im asking if there is anything wrong written in the script.
Technically, everything in the script that does not apply to your systems is wrong...

You have said your self that when you run it manually it works, so when does it not work as expected?
And what are the exact error(s)?
 
Old 06-05-2019, 01:34 PM   #33
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by BW-userx View Post
I'd suppose you'd have to change your system time date to test it as well, yes?
That's too easy.

Code:
DOW=$( date +'%w' )
DOW=1              # Test the Monday code
Change the if statements to reference $DOW.
 
Old 06-05-2019, 01:55 PM   #34
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
That's a misapprehension I see often: no, a #! is ONLY needed when you want a specific shell (or application) to run it.
The shebang is also needed if you want file(1) to be able to tell you that it's something other than "ASCII text". Why omit it?
 
Old 06-05-2019, 02:36 PM   #35
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by rnturn View Post
That's too easy.

Code:
DOW=$( date +'%w' )
DOW=1              # Test the Monday code
Change the if statements to reference $DOW.
well happy is me, someone is thinking out of the box, as I wasn't going to put every way to test.. still that does not change it for me, I still could not test it because why? and for such a detailed script and not knowing how to test it.. well again I am not really wanting to type every little detail about this script and everything on it ... so yeah.. you figure that part out too. cheers!!
 
Old 06-05-2019, 04:35 PM   #36
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by rnturn View Post
The shebang is also needed if you want file(1) to be able to tell you that it's something other than "ASCII text".
That has already been done by setting the eXecutable bit on it:
Code:
cat script
echo This is a 1-line script
 $ file script
script: ASCII text executable
In fact most of my scripts DO have a shebang, but of #!/bin/sh, to tell that it
does not use any bash-specific features.
 
Old 06-05-2019, 06:53 PM   #37
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ehartman View Post
That has already been done by setting the eXecutable bit on it:
Code:
cat script
echo This is a 1-line script
 $ file script
script: ASCII text executable
In fact most of my scripts DO have a shebang, but of #!/bin/sh, to tell that it
does not use any bash-specific features.
Interesting... When I place 'code' into a file w/o a shebang line it is identified as "ASCII text".

If I make it executable ("chmod u+x ...") file(1) identifies it as... "ASCII text".

[scratching my head now]
 
Old 06-05-2019, 09:34 PM   #38
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
In debian, if you do not override the default when you create your user, it will run whatever /bin/sh points at as your shell. It might look like bash, it might act like bash, but it might not BE bash. I rather like the bash extras to tell how many characters are in a string, and to extract a, or a set of, character(s) at a particular position. A lot of which doesn't work in dash.

$ ls -l $(which sh)
Code:
lrwxrwxrwx 1 root root 4 Jan 23  2017 /bin/sh -> dash
 
Old 06-07-2019, 03:34 AM   #39
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
shellcheck was mentioned several times to you. Why don't you give it a try? You don't need to wait for everyone, it will give you the answer immediately. And you will see the errors.

come back if you fixed all the errors reported by shellcheck - or if you have problem fixing any of them.
shellcheck isnt giving me any error that is wrong with the script; The script runs.
 
Old 06-07-2019, 03:35 AM   #40
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Shadow_7 View Post
Also no #! at the top of the script. If you're running it ./, then it wont know what shell to use. And systems default to different shells. Like debian defaults to dash, bsd to tch?, and other quirks.
Yup, forgot about that one. It defaulted to the default share and worked but I forgot it is needed.

Quote:
Originally Posted by Shadow_7 View Post
Also, if you "require" external programs, why not check for them in the script instead of being lazy and having a comment that it is required?

Code:
if [[ ! $(which ipmi) ]]; then
  echo "ipmi NOT detected"
  exit 1
fi
You summed it up: Laziness
 
Old 06-07-2019, 03:36 AM   #41
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by BW-userx View Post
I can tell you yes, it looks fine and dandy to me
Thats all I needed. Thanks
 
Old 06-07-2019, 03:40 AM   #42
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by dc.901 View Post
You have said your self that when you run it manually it works, so when does it not work as expected?
And what are the exact error(s)?
The only other thing I suspect is the crontab but:

*/5 * * * * /bin/bash /root/scripts/r710fanscript.sh >/dev/null 2>&1
 
Old 06-07-2019, 05:22 AM   #43
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,770

Rep: Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933
I agree with astrogeek's post.

You still have not posted where your script is failing.

Program syntax is correct but you have not paid attention to the note about octal numbers.
 
Old 06-07-2019, 05:46 AM   #44
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by riahc3 View Post
The only other thing I suspect is the crontab but:

*/5 * * * * /bin/bash /root/scripts/r710fanscript.sh >/dev/null 2>&1
The way I troubleshoot why a script is not running via cron is change /dev/null to a file; for example:


Code:
*/5 * * * * /bin/bash /root/scripts/r710fanscript.sh >>/tmp/r710fanscript.out 2>&1
Then, review the file /tmp/r710fanscript.out after the job runs to determine what's happening; in this case looks like you want to run every 5-minutes.
This will help fix any errors. After all issues are resolved, change the crontab entry back to /dev/null...
 
  


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 inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
how to get second shell script flag value from the first shell script amit_pansuria Programming 2 08-08-2008 08:19 AM
Call One shell script from another shell script Sundaram Linux - Software 5 10-13-2006 03:59 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
why my shell script is not working linuxlah Linux - General 4 08-01-2002 08:39 AM

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

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