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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-10-2004, 12:00 AM
|
#1
|
LQ Newbie
Registered: Jan 2004
Location: Virginia
Distribution: Fedora Core 2
Posts: 27
Rep:
|
shell script won't execute
Hey everyone, I'm developing my first linux shell script and for some reason I can't get it to execute. The script is designed to create new users on the system.
I've placed the script in a /root/bin (a directory I created), and changed the permissions to 0750. When I try to execute the script from the root prompt, I get:
[root@coupweb bin] #./newuser tim
: bad interpreter : No such file or directory
What does this mean? I've included the script below if that helps.
Once again, thanks so much.
Matt
------------------------------------------------------------------------------
#!/bin/bash
# newuser script
# makes new user on coupweb.newcomb.virginia.edu
#
# create user and prompt for password
useradd $1
passwd $1
#
# add user apache (http server) to user's group
# sets group id for user's default group
tid=`id -g $1`
# defines default entry in /etc/group
fromStr=$1:x:$tid:
# defines modified entry in /etc/group with user apache added
toStr=$1:x:$tid:apache
# replaces fromStr with toStr in /etc/group
replace $fromStr $toStr -- /etc/group
#
# make public_html and cgi-bin directories with u=rwx,g=rx,o=rx
mkdir ~$1/public_html -m 0755
mkdir ~$1/public_html/cgi-bin -m 0755
#
# add user to ftp log
echo $1 >> /etc/vsftpd.chroot_list
|
|
|
08-10-2004, 12:09 AM
|
#2
|
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290
|
The ./newuser tells the shell to execute the script with the name newuser in the current directory. Unless you're in /root/bin, this is not going to work. Simply use newuser or /root/bin/newuser if you want to be explicit about it.
|
|
|
08-10-2004, 12:16 AM
|
#3
|
Member
Registered: Oct 2003
Location: Iowa
Distribution: LFS 5.0, building 6.3, win98se, multiboot
Posts: 288
Rep:
|
That error message can be caused by a permission problem. I'd check the perms on the /root and /root/bin directories. Also, if you use several partitions the options on the partition in which /root/bin resides needs to be mounted with the exec option.
|
|
|
08-10-2004, 11:00 AM
|
#4
|
LQ Newbie
Registered: Jan 2004
Location: Virginia
Distribution: Fedora Core 2
Posts: 27
Original Poster
Rep:
|
Hmm...using both 'newuser' and '/root/bin/newuser' didn't work--both gave me the bad interpreter error from before. Neither did cd'ing to the /root/bin directory and then using newuser and ./newuser.
Also, the permissions on /root are 0750 and the perms on /root/bin are 0750. This seems to be what I want--root can rwx the directories, the admins group can only read and execute in the directories, and other users cannot access the directories (I did this for security reasons). I am not using any partitions (except /swap and /), so I'm not sure how that plays a role.
Any other ideas? Thanks again!
|
|
|
08-10-2004, 12:29 PM
|
#5
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
Can you execute the script like this?
bash /root/bin/newuser testacct
If you can, then I would guess one of two things:
1. The #!/bin/bash line is not the very first line of the file
2. The location of bash is not /bin/bash, and you would need to update it in the script
If you can't execute it with the command above, then it would seem your system doesn't have bash installed.
|
|
|
08-10-2004, 02:20 PM
|
#6
|
LQ Newbie
Registered: Jan 2004
Location: Virginia
Distribution: Fedora Core 2
Posts: 27
Original Poster
Rep:
|
After some googling, I figured out my problem....I had developed the script in Notepad on my Windows box at home and then ftp'd it to the linux box at work, and I had forgot that Windows leaves '\r' carriage returns that don't show up when I looked at the file on my linux box. I used replace to get rid of them, and now everything works fine.
Don't worry, as soon as I get some more familiarity with Linux, I'll be switching over at home too. 
|
|
|
08-10-2004, 02:22 PM
|
#7
|
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851
Rep:
|
quick question, because i didnt know what
will you paste the url you got that information from?
|
|
|
08-10-2004, 02:30 PM
|
#8
|
LQ Newbie
Registered: Jan 2004
Location: Virginia
Distribution: Fedora Core 2
Posts: 27
Original Poster
Rep:
|
|
|
|
All times are GMT -5. The time now is 11:28 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|