Set password in bash script without manual entry-Solaris 10


 
Thread Tools Search this Thread
Operating Systems Solaris Set password in bash script without manual entry-Solaris 10
# 1  
Old 01-07-2016
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 great.

--stdin, echo -e, expect is not installed and we cannot use it.... nothing works
so if anyone have any idea please let me know...

We are using Solaris 10,

Last edited by Jaffakeks; 01-07-2016 at 03:38 PM.. Reason: misspeling
# 2  
Old 01-07-2016
The following is pasted from various scripts, use it with care!
Code:
PATH=/bin:/usr/bin:/usr/sbin:/usr/sfw/bin:/opt/csw/bin
export PATH

# Solaris has no tool to set a password non-interactively.
# Using "expect" has many risks. So we directly edit /etc/shadow.
sol_pwd()
{
ETCSHADOW=/etc/shadow
DATECHG=`perl -e 'print int time/86400'`
# Backup with owner/permission
if
  cp -p ${ETCSHADOW} ${ETCSHADOW}- &&
  cp -p ${ETCSHADOW} ${ETCSHADOW}.aux &&
# Overwrite the files; owner/permission and line order remains
  awk '
    BEGIN { FS=OFS=":" }
    ($1==user) { $2=hash; $3=datechg }
    { print }
  ' user="$ID" hash="$HASH" datechg="$DATECHG" < ${ETCSHADOW} > ${ETCSHADOW}.aux
then
  # *LK* in pw-hash and 0 in lastchg was overwritten. passwd -u is not necessary
  mv -f ${ETCSHADOW}.aux ${ETCSHADOW}
fi
} # sol_pwd

# main

echo "Enter user:"
read ID
echo "Enter pw:"
read PASS
if [ -z "$ID" ] || [ ${#PASS} -lt 3 ]
then
  exit
fi
HASH=`echo "${PASS}" | openssl passwd -stdin` || exit
sol_pwd


Last edited by MadeInGermany; 01-07-2016 at 04:37 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

2. HP-UX

Sudo entry required to set permission similar to ROOT without using password (PASSWD) change optio

Hi All I had installed sudo in HP UX 11.3 and it is working fine but not able to make entry required to set permission similar to ROOT without using password (PASSWD) change option for define user in /etc/sudoers file Please help if some know the syntex? :confused::wall: (2 Replies)
Discussion started by: deviltech
2 Replies

3. Shell Programming and Scripting

Automatic su password entry script

Before I start, two things. 1) Yes I know it's bad practice and obomination to all things holy, but I'm not a sys admin at JP Morgan, I'm a hobbyist tooling about in a VM, in my pants, at home. 2) If you are just going to flame for even considering hardcoding a root password, thanks, I get... (2 Replies)
Discussion started by: 3therk1ll
2 Replies

4. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

5. Shell Programming and Scripting

Script to set password in HP-UX 11.31

Hi, I am unable to set the password remotely. I am using the script as below: ep=`echo "$p" | /usr/lbin/makekey` ssh -t $i "/usr/local/bin/sudo useradd -c "$user_c" -m -d /home/$user_id -s /bin/ksh $user_id; /usr/local/bin/sudo /usr/sam/lbin/usermod.sam -F -p $ep $user_id" The... (0 Replies)
Discussion started by: Kits
0 Replies

6. Shell Programming and Scripting

script to set the password from *LK* to *NP*

okay here I go again... I have created a script which adds new user to /etc/password and which inturn creating a locked password in /etc/shadow but I am expecting to have *NP* for that particular user.Can someone help me with a script which can set the password for a particular user to NP in... (1 Reply)
Discussion started by: sintilash
1 Replies

7. Shell Programming and Scripting

No Manual Entry

Hi, While executing the following command i am getting output as command not found. iostat output: command not found Also, man iostat is displaying "NO Manual Entry" Why is it so? (5 Replies)
Discussion started by: salil2012
5 Replies

8. Shell Programming and Scripting

no manual entry for awk

Hi, there is no manual entry for awk? how can i make the awk works? thanks (1 Reply)
Discussion started by: shanshine
1 Replies

9. Solaris

How to set Root password age limit in Solaris 9/10

Hi Friends, Can anyone tell me how can I set the password age limit for root user to 14 days....??? Also would like to add following for root password; min-alpha --- 4 min-other --- 1 min-length -- 6 min-diff ----- 3 How can I do these on command line....??? Regards, jumadhiya (7 Replies)
Discussion started by: jumadhiya
7 Replies

10. UNIX for Dummies Questions & Answers

No manual entry for

I don't seem to be able to get man pages up for any command. When I try the "No manual entry for..." message is displayed. When checking my $MANPATH variable I get the following /opt/SUNconn/man: However, when I check this directory it doesn't exist. Searching for any man directories results... (3 Replies)
Discussion started by: FattyLumpkin
3 Replies
Login or Register to Ask a Question