Reputation: 1
As I am trying to learn bash shell, I want to have some idea how can I add or modify the user in Bash Shell script?
Upvotes: 0
Views: 1030
Reputation: 9415
Quick Ex:
Adding an user:
createuser.sh
#!/bin/sh
user=$1 #first argument
apache="www-data"
passuser=$2 # second argument
newpasswd=$(perl -e 'print crypt($ARGV[0], "S@LtStR!Ng")' $passuser)
createuser='/usr/sbin/useradd' # PATH to `useradd` package
##create and update password, then assign the apache group to the user
$createuser -d /home/$user -g $apache -m -s /bin/bash -p $newpasswd $user
Calling:
root@ip-ad-2as2-ds:#./createuser.sh test test1234
This way you can control the modify-user script, just change the createuser
variable to have the proper modify-user (usermod
) package.
Upvotes: 1