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 |
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.
|
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.
|
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! |
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. |
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. :) |
quick question, because i didnt know what
will you paste the url you got that information from? |
|
All times are GMT -5. The time now is 02:53 AM. |