Shell Scripting Help...

Discussion in 'Programming/Scripts' started by webking, Apr 4, 2007.

  1. webking

    webking New Member

    Hi all,

    How difficult is it to get this pseudo code to work under SHELL? This is the task I do every day. I m not sure how to start it. can anyone help?

    useradd username
    usermod -g username username
    passwd username
    vi /etc/passwd
    define home dir
    cd ~username
    remove all data
    then go to /home/usrbak
    cp username.tar.gz to /tmp
    cd tmp
    gzip -d username.tar.gz
    tar -xf username.tar
    mv * ~username
    vi /usr/local/apache/conf/include-conf/vhosts
    add the domain within the vhost
    cd ~username
    chown -R username:username .
    chmod -R 755 .
    service httpd restart

    Any assistance would be helpful. Thanks in adv.
  2. falko

    falko Super Moderator Howtoforge Staff

    You could write a little script for it.
  3. cfajohnson

    cfajohnson New Member

    Most of what you are doing can be done with useradd itself. Read the man page.

    The (moderately) tricky part is encrypting the password. I use a compiled C program as a front end to crypt(3):

    NAME: crypt.c
    AUTHOR: Chris F.A. Johnson
    DATE: 2003-01-23
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <unistd.h>

    main(int argc, char *argv[])
    char *passwd;
    char buf[1024];
    char *salt;

    if (argc > 1)
    salt = argv[1];
    /* salt = "$1$!@#$%^&*"; */
    salt = NULL;

    if ( buf[strlen(buf)-1] == '\n' )
    buf[strlen(buf) - 1] = '\0';
    printf( "%s\n", encrypt(buf, salt));

    return 0;

    Do not use vi in a script. Describe what you want to do, and script it directly.
  4. sjau

    sjau Local Meanie Moderator

    Well, I think it's not that hard to make a bash script that does this...

Share This Page