User avatar
hanako13
Posts: 3
Joined: Wed May 04, 2016 9:36 am

Problems with Linux Shell Scripts!

Wed May 04, 2016 9:49 am

Hi everyone,
I am just nearing the end of my Computing GCSE controlled assessment, and one of the questions is to write a shell script to automate adding new users and adding them to a group (in this case, either "teachers" or "students"). I found this website showing a script to add users with passwords, but I've copied it into a shell script on my Raspberry Pi, and I've got an error saying that I don't have permissions to run the program. I'm trying to run it from [email protected] and I've used chmod -x to give execute permissions, but it's still not running.

Any ideas? I would really appreciate some help as the due date for the controlled assessment is this week! :? I'm the only girl in my class and none of the boys will help me... :(
Attachments
13 forum two.png
13 forum two.png (7.54 KiB) Viewed 1269 times
13 forum one.png
13 forum one.png (24.79 KiB) Viewed 1269 times

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Problems with Linux Shell Scripts!

Wed May 04, 2016 9:55 am

"chmod -x" removes execute permission. You want "chmod +x".

There are a couple of errors in the script as well. It is essential to have spaces inside the square brackets in lines like:

Code: Select all

if [ $? -eq 0 ]; then

User avatar
joan
Posts: 14469
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Problems with Linux Shell Scripts!

Wed May 04, 2016 9:56 am

You have made the script non executable.

Try

chmod +x /usr/local/bin/addscript

User avatar
hanako13
Posts: 3
Joined: Wed May 04, 2016 9:36 am

Re: Problems with Linux Shell Scripts!

Wed May 04, 2016 6:15 pm

Thanks, I'll try using chmod +x and fixing the spacing problems in my next lesson and see how it goes. I'll let you all know if there's any more problems!

User avatar
B.Goode
Posts: 8987
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Problems with Linux Shell Scripts!

Wed May 04, 2016 7:05 pm

Since this is part of a controlled assessment, it would probably be wise to include a description of what problems you encountered and how you solved them.

Teachers and examiners read online forums too... !

User avatar
experix
Posts: 204
Joined: Mon Nov 10, 2014 7:39 pm
Location: Coquille OR
Contact: Website

Re: Problems with Linux Shell Scripts!

Thu May 05, 2016 12:49 pm

Was the assignment "understand the problem and write a program to solve it", or was it "find an answer somewhere on the web and copy it without understanding anything"?

User avatar
hanako13
Posts: 3
Joined: Wed May 04, 2016 9:36 am

Re: Problems with Linux Shell Scripts!

Thu May 05, 2016 6:59 pm

Yes, I've been sourcing any websites or tutorials that I've been using and writing about all the errors I've come across. Thanks for the tip!

I won't be copying the code directly into my assessment at all - the shell script I have been designing and writing myself to add users isn't working, and so I'm researching other people's scripts to understand how to write and fix my own.

Return to “General programming discussion”