solaris create password in a script and continue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting solaris create password in a script and continue
# 1  
Old 10-25-2012
solaris create password in a script and continue

Below is my code to create a user account but it doesn't take a password automatically. I have to run the password command seperately to do this
What I want to do is to be able to accept the password in a script.
In linux with the "useradd' command you can give the "-p" flag to accept the password

Code:
 #!/opt/csw/bin/bash 
clear
# Script to add a user to this Linux system
        if [ $(/usr/xpg4/bin/id -u) -eq 0 ]; then                                     # check if user is root

        read -p "Enter Group Name : " groupname                 # Enter group name
        while [ -z $groupname ]|| egrep "^$groupname" /etc/group 1>/dev/null;
        do
        echo -ne "Either group exists or you entered a blank, enter groupname again: ";read -e  groupname
        done

        echo -ne "\nPlease Enter your Group ID Number: ";read -ern3 gid
        while [[ ! $gid =~ ^[0-9]+$ ]]||egrep $gid /etc/group >/dev/null;
        do
        echo -ne "Please re-enter your group id positive intergers only: ";read -ern3 gid
        done

        echo -ne "\nPlease Enter your User ID Number: ";read -ern5 uid
        while [[ ! $uid =~ ^[0-9]+$ ]]||egrep $uid /etc/passwd >/dev/null;
        do
        echo -ne "\nPlease re-enter your uid positive intergers only: ";read -ern5 uid
        done

        echo -ne "\nEnter a Comment : "; read -e comment
        commentstatic="Staging Account"

        echo -ne "\nEnter your Staging FTP directory location.......... "; read -e ftpdir
        while [ ! -d "$ftpdir" ];
        do
        echo -ne "\n$ftpdir Directory Not Found! Please re-enter: "; read ftpdir
        done

        username="s"$groupname                                   #getting username from groupname
        
        /opt/csw/bin/gsed -e '/ftp/s/$/,'"$username"'/' -i /etc/group # this line is to add user to ftp group.........."

        echo -e "\nAdding group $groupname......."                           #Adding group to group file
        groupadd -g $gid $groupname
        echo -e "Finished adding $groupname to group file......."           

        echo -e "\nAdding user to system.........."
        /usr/sbin/useradd -u $uid -g $groupname -c "$comment $commentstatic" -d /forms1/prodenv/$groupname $username
        sleep 2
        echo -e "\nFinished adding $username to password file......."             #Adding user to password file

        echo -e "\nLinking source directory to home directory......."
        cd /forms1/prodenv
        ln -s /stage001/stageenv/$username $groupname   
        echo -e "\nDone linking home directory......"   

        echo -e "\nLinking source storage directory to home storage directory......."
        cd /forms/
        ln -s /stage001/stageenvsa/${username}sa ${groupname}sa 
        echo -e "\nDone linking storage directory......"        

        echo -e "\nSetting security on directories................"
        chown $username:$groupname /stage001/stageenv/$username 
        chown $username:$groupname /stage001/stageenvsa/${username}sa
        chmod 775 /stage001/stageenv/$username
        chmod 775 /stage001/stageenvsa/${username}sa
        echo -e "\nFinished setting security on directories................"

        echo -e "\nSetting up the FTP directory................"
        cd /ftp
        ln -s $ftpdir $username
        echo -e "\nSetting security on FTP directory................"   
        chown $username:ftp $ftpdir
        chmod 775 $ftpdir
        echo -e "\nFinished setting security on FTP directory................"
        
        echo -e "\nSetting up services file................"
        serviceadd=`tail -1 /etc/services | awk '{print $2}'| cut -c 1-5`
        let serviceadd++
        echo -e "$username""trck" "\t$serviceadd/tcp" "\t\t# $comment Staging Svc Account" >> /etc/services
        echo -e "Finished setting up services file................"
        echo ""
        echo ""
        fi

# 2  
Old 10-25-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Set password in bash script without manual entry-Solaris 10

Hi I have a root script which is setting up user and his dirs and so on. After I create user and set up all the necessary I have to manually set user password. I try all possible ways what google find me and nothing works for me. If maybe one of you have a solution for my problem it will be... (1 Reply)
Discussion started by: Jaffakeks
1 Replies

2. UNIX for Advanced & Expert Users

Need a exit from sftp if its ask for password and continue to run remaining part of script.

Hi I am checking status of sftp in Health check script, sftp command is used to connect the server with secure RSA key, which is successfully get connected most of the time but in some case if RSA key ask for password then I need to exit sftp command after few second and continue to run... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

solaris create password in a script and continue

:eek:Below is my code to create a user account but it doesn't take a password automatically. I have to run the password command seperately to do this What I want to do is to be able to accept the password in a script. In linux with the "useradd' command you can give the "-p" flag to accept the... (3 Replies)
Discussion started by: slufoot80
3 Replies

4. Shell Programming and Scripting

solaris create password in a script and continue

:eek:Below is my code to create a user account but it doesn't take a password automatically. I have to run the password command seperately to do this What I want to do is to be able to accept the password in a script. In linux with the "useradd' command you can give the "-p" flag to accept the... (1 Reply)
Discussion started by: slufoot80
1 Replies

5. UNIX for Advanced & Expert Users

Can we Automate the User creation and setting password through a script in solaris 10

Hi, I am using Solaris 10 OS and Bash shell.Is there any way can we automate User creation and setting passwords through a script or any freeware tool. Advance thanks for your response. (1 Reply)
Discussion started by: muraliinfy04
1 Replies

6. Shell Programming and Scripting

script to create files on solaris 10

Hello, To learn ZFS, i try to create pool . and for that i want create 10 files with 512MB (because i dont have multiple disks and multiple controllers) ADMIT THAT THIS IS TEN HIGH-PERFORMANCE HARD DRIVES To get this 10 files,all of them have the same size : 512MB, I do these... (0 Replies)
Discussion started by: herbich1985
0 Replies

7. Shell Programming and Scripting

Create script for change root password via SSH

HI I 'm new shall script and unix. I want to create script for change password root by ssh-keygen command . I have 50 servers and I want ot login ot the servers via ssh by type ones password and can login every machines.The script ssh-keygen must ot generate key every weekly than it send new... (2 Replies)
Discussion started by: pellnapook
2 Replies

8. Shell Programming and Scripting

Create new user account and password in shell script

I am trying to create a shell script that will: check if a specific user already exists if not, create a specific group and create the user in that group assign a password to that user, where the password is passed in as a parameter to the script The problem that I need help with is 3 on... (4 Replies)
Discussion started by: killuane
4 Replies

9. Solaris

How to create a simple background script on Solaris

I have a local account for a unix server. The idle timeout for the account is around 10 mins. I have to login to the server multiple times during the day. Is there a way to increase the idle timeout or may be a script that I can run on background so it is not idle. Something like echo date every 9... (3 Replies)
Discussion started by: vinaysa
3 Replies
Login or Register to Ask a Question