Results 1 to 4 of 4

Thread: Bash Scripting

Hybrid View

  1. #1
    cuban
    Guest

    Bash Scripting

    I have a script to call on a file

    #!/bin/sh
    #Define Variables
    username=`awk -F: '{print $1}' /tmp/new.webhost`
    userweb=`awk -F: '{print $2}' /tmp/new.webhost`
    userpass=`awk -F: '{print $3}' /tmp/new.webhost`

    #Do this!
    useradd -g 200 -s /bin/false -d /webs/$userweb $username
    chmod -R 755 $userweb
    chown -R $username $userweb
    chgrp -R webhosting $userweb
    echo $userpadd | passwd $username --stdin
    echo "<VirtualHost 216.110.5.16>" >> /etc/httpd/conf/named-virtual.conf
    echo "DocumentRoot /webs/$userweb" >> /etc/httpd/conf/named-virtual.conf
    echo "ServerName $userweb" >> /etc/httpd/conf/named-virtual.conf
    echo "</VirtualHost>" >> /etc/httpd/conf/named-virtual.conf
    /etc/rc.d/init.d/httpd restart


    My problem is when it reads a file with more than one line of delimited text, it adds that field in all at the same time! Instead of running it many times!

    [-/tmp/new.webhost-]
    cuban:cuban.com:cubapass
    usa:usa.com:uspass
    [-/tmp/new.webhost-]


    useradd -g 200 -s /bin/false -d /webs/cuban.com
    usa.com cuban usa

    I would like for it just it repeate the useradd, and the rest of the commands by running the line over and over... Is this possible?

    How can I solve this?

  2. #2
    JimH
    Guest

    Re: Bash Scripting

    We are really pushing the limits of my limited bash scripting knowledge now!
    Try this for a quick fix and see if it works. Guess I will just have to go out a get a book on bash scripting. ;D

    #!/bin/bash

    #Define Variables
    READ_FILE=/tmp/new.webhost

    #Add users
    cat $READ_FILE &#124; while read line
    do
    username=`echo $line &#124; cut -f1 -d":"`
    userweb=`echo $line &#124; cut -f2 -d":"`
    userpass=`echo $line &#124; cut -f3 -d":"`

    echo "Adding user: " $username

    /usr/sbin/useradd -g 200 -s /bin/false -d /webs/$userweb $username
    /bin/chmod -R 755 $userweb
    /bin/chown -R $username $userweb
    /bin/chgrp -R webhosting $userweb
    echo $userpass &#124; passwd $username --stdin
    echo "<VirtualHost 216.110.5.16>" >> /etc/httpd/conf/named-virtual.conf
    echo "DocumentRoot /webs/$userweb" >> /etc/httpd/conf/named-virtual.conf
    echo "ServerName $userweb" >> /etc/httpd/conf/named-virtual.conf
    echo "</VirtualHost>" >> /etc/httpd/conf/named-virtual.conf

    done
    #I put this here assuming you can restart once after all the new users have been added.
    /etc/rc.d/init.d/httpd restart

    exit 0


  3. #3

    Re: Bash Scripting

    I have not even touched bash scripting...looks well ummm...different.

    Aragorn
    If you give a man a fire he'll be warm, if you light the man on fire he'll be warm for life.

  4. #4
    cuban
    Guest

    Re: Bash Scripting


    We are really pushing the limits of my limited bash scripting knowledge now!
    Try this for a quick fix and see if it works. Guess I will just have to go out a get a book on bash scripting. ;D

    Works really well, thank you!

Similar Threads

  1. Bash scripting and the stderr
    By 10Dedfish in forum Programming
    Replies: 2
    Last Post: 12-30-2003, 01:12 PM
  2. bash scripting question
    By seanmclemon in forum Programming
    Replies: 7
    Last Post: 09-07-2003, 12:58 AM
  3. Bash scripting question
    By kenshi in forum Programming
    Replies: 6
    Last Post: 01-02-2003, 08:36 PM
  4. need some bash scripting help
    By mountainman in forum Programming
    Replies: 2
    Last Post: 08-30-2002, 12:44 PM
  5. bash scripting and quoting
    By in forum Programming
    Replies: 5
    Last Post: 03-21-2002, 12:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •