Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Newb Bash script question


  • Please log in to reply
11 replies to this topic

#1 Ravenbar

Ravenbar

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:09:53 AM

Posted 01 February 2016 - 09:55 PM

If I have an error that refers to a specific line of the script, is it that many lines down in executed lines or in does it count lines of comments?

Example:

Error: File /etc/sensors.d/mkdev.sh, line 6: Invalid keyword


#!/bin/bash

# Here you can set several defaults.

# The number of devices to create (max: 256)
NUMBER=32

# The owner and group of the devices
OUSER=root
OGROUP=root
# The mode of the devices
MODE=600

# This script doesn't need to be run if devfs is used
if [ -r /proc/mounts ] ; then
if grep -q "/dev devfs" /proc/mounts ; then
echo "You do not need to run this script as your system uses devfs."
exit;
fi
fi

i=0;


Is the error in the line that reads "Number=32, or in the line that reads "if grep -q "/dev devfs" /proc/mounts ; then"?

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 


BC AdBot (Login to Remove)

 


#2 Guest_hollowface_*

Guest_hollowface_*

  • Guests
  • OFFLINE
  •  

Posted 01 February 2016 - 10:56 PM

is it that many lines down in executed lines or in does it count lines of comments?

Should be the number of lines in the file, which in this case seems to be "NUMBER=32", but there is nothing wrong with that line, so I'm not sure what the problem is.

 

Demo Screenshots:

1. http://i.imgur.com/yBb9BhN.png

2. http://i.imgur.com/Ek8AiHP.png

3. http://i.imgur.com/xcivjO2.png



#3 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male

Posted 02 February 2016 - 02:11 AM

Hi Ravenbar

 

Where you currently have

if grep -q "/dev devfs" /proc/mounts ; then
echo "You do not need to run this script as your system uses devfs."

... can you try

if grep -q "/dev devfs" /proc/mounts
then
echo "You do not need to run this script as your system uses devfs."

... and report back?

 

BTW :welcome: to BC and to the Linux and Unix section.

 

Enjoy

 

:wizardball: Wizard



#4 Ravenbar

Ravenbar
  • Topic Starter

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:11:53 PM

Posted 02 February 2016 - 05:29 PM

I did the change, rebooted and am still getting the same error.

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 


#5 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:09:53 AM

Posted 02 February 2016 - 09:35 PM

Sadly my knowledge here is very limited.

 

What Linux are you in, and what is your grep version? Mine is v2.21, from <man grep>.

info grep

... provides more of the manual.

 

Good luck

 

:wizardball:



#6 Ravenbar

Ravenbar
  • Topic Starter

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:11:53 PM

Posted 02 February 2016 - 10:18 PM

I'm certain the "Invalid Keyword" is in the line "NUMBER=32" as I added deleted blank lines and the line number changed it added lines were about be but didn't if they were below.

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 


#7 Ravenbar

Ravenbar
  • Topic Starter

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:09:53 AM

Posted 02 February 2016 - 10:28 PM

Sadly my knowledge here is very limited.
 
What Linu/proc/mountsx are you in, and what is your grep version? Mine is v2.21, from <man grep>.

info grep
... provides more of the manual.
 
Good luck
 
:wizardball:


Grep Version is 2.16.

Running Linux Mint 17.3"Rosa"

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 


#8 Guest_hollowface_*

Guest_hollowface_*

  • Guests
  • OFFLINE
  •  

Posted 02 February 2016 - 11:09 PM

I tried running:

if [ -r /proc/mounts ] ; then
if grep -q "/dev devfs" /proc/mounts ; then
echo "You do not need to run this script as your system uses devfs."
exit;
fi
fi

on my machine to see if I got any errors (I added an else statement so I could verify it actually ran). I didn't get any errors from it.

 


I'm certain the "Invalid Keyword" is in the line "NUMBER=32"

The line is valid as is, but try using "export NUMBER=32" instead. This just means the variable will be available to subshells.

 

When you executed the script exactly what command did you type?



#9 Ravenbar

Ravenbar
  • Topic Starter

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:09:53 AM

Posted 03 February 2016 - 12:23 AM

I tried running:
 

if [ -r /proc/mounts ] ; then
if grep -q "/dev devfs" /proc/mounts ; then
echo "You do not need to run this script as your system uses devfs."
exit;
fi
fiDesktop
on my machine to see if I got any errors (I added an else statement so I could verify it actually ran). I didn't get any errors from it.
 
 

I'm certain the "Invalid Keyword" is in the line "NUMBER=32"

The line is valid as is, but try using "export NUMBER=32" instead. This just means the variable will be available to subshells.
 
When you executed the script exactly what command did you type?


It's executed as part of the "sensors" command.

The entire mkdev.sh file:

#!/bin/bash

# Here you can set several defaults.

# The number of devices to create (max: 256)
export number=32



# The owner and group of the devices
OUSER=root
OGROUP=root
# The mode of the devices
MODE=600

# This script doesn't need to be run if devfs is used
if [ -r /proc/mounts ] ; then
if grep -q "/dev devfs" /proc/mounts
then
echo "You do not need to run this script as your system uses devfs."
exit;
fi
fi

i=0;

while [ $i -lt $number ] ; do
echo /dev/i2c-$i
mknod -m $MODE /dev/i2c-$i c 89 $i || exit
chown "$OUSER:$OGROUP" /dev/i2c-$i || exit
i=$[$i + 1]
done
#end of file


Edited by Ravenbar, 03 February 2016 - 12:26 AM.

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 


#10 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male

Posted 03 February 2016 - 02:16 AM

Hi, me again.

 

Is the Rosa Cinnamon or MATE, or other? I have both the mentioned ones.

 

Is

/dev/i2c-0

one of the likely or desired outcomes?

 

:wizardball: Wizard

 

BTW - no need to answer the Desktop question - have checked and both are running v2.16. My reference to v2.21 is from Ubuntu 15.10 MATE.

Edited - added BTW


Edited by wizardfromoz, 03 February 2016 - 02:46 AM.


#11 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,420 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:09:53 AM

Posted 03 February 2016 - 09:24 AM

As everyone has stated there isn't anything wrong with that script... I'm just throwing this out there just to try.

 

Make sure you are in a bash shell when running the command. Just type

bash

in the shell to drop to your bash shell, then try running the sensors command again. The only thing I can think of is its trying to run in another shell and doesn't like that variable, which is possible.


OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#12 Ravenbar

Ravenbar
  • Topic Starter

  • Members
  • 125 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NY
  • Local time:11:53 PM

Posted 03 February 2016 - 05:53 PM

Hi, me again.
 
Is the Rosa Cinnamon or MATE, or other? I have both the mentioned ones.
 
Is

/dev/i2c-0
one of the likely or desired outcomes?
 
:wizardball: Wizard
 
BTW - no need to answer the Desktop question - have checked and both are running v2.16. My reference to v2.21 is from Ubuntu 15.10 MATE.
Edited - added BTW


KDE

Desktops: "John2" Custom, Gigabyte F2A88Xm-D3H, AMD 6A-5400K Trinity 3.6Ghz Dual-Core APU, 16Gb DDR3  HyperX Fury 1866Mhz RAM, 120Gb Crucial Force LS SSD OS) Linux Mint 17.3, 320Gb Raid1 array consisting of (1) Seagate ST320LT020-9YG14 & (1) Fujitsu MZH2320B

Francisco: HP pavilion p7-1080t upgraded with 16Gb ram. Windows 7. Used only for Gaming

Server.GaltsGulch: HP Elite 8300 Small Form Factor, i7-3770, 16Gb ram, Kingston SSDNow 120Gb SSD, 3Tb storage HDD, Fedora Linux/Avahi, Headless

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users