Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    editing script to create a default web page

    Hello everyone

    The title of this post may sound like it's real easy and simple enough for a noob to do but my situation isn't noobish.

    I have this script that i found on the internet that i wish to edit and create a new user and set a pass word AND create a default web page in the /var/www/html directory.

    This is the script with my edits included. The commented out field are my own editing.....

    # Script to add a user to Linux system
    if [ $(id -u) -eq 0 ]; then
    	read -p "Enter username : " username
    	read -s -p "Enter password : " password
    	egrep "^$username" /etc/passwd >/dev/null
    	if [ $? -eq 0 ]; then
    		echo "$username exists!"
    		exit 1
    		pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
    		useradd -m -p $pass $username
    		[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
    #touch index.php /var/www/html
    	echo "Only root may add a user to the system"
    	exit 2
    I know this may seem like a weird way of doing it but please forgive me, i haven't worked on linux in years and am trying to get back in the swing of it. My main points are
    - Make a file in the /var/www/html folder that is a .php or .html extension
    - How could i create a default html / php web page from whithin the script? if possible?

    Thanks in advanced,

  2. #2
    Just Joined! cfajohnson's Avatar
    Join Date
    May 2007
    Toronto, Canada

    You should make a directory for the user, then create the HTML file:
    mkdir /var/www/html/$username || exit 1
     printf "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">\n"
     printf "<head>\n <title></title>\n </head>\n"
     printf " <body>\n  <h1></h1>\n"
    } > /var/www/html/$username/index.html

Posting Permissions

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