1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#!/bin/sh adduser() { USER=$1 PASSWD=$2 shift ; shift COMMENTS=$@ useradd -c "${COMMENTS}" $USER if [ "$?" -ne "0" ]; then echo "Useradd failed" return 1 fi passwd $USER $PASSWD if [ "$?" -ne "0" ]; then echo "Setting password failed" return 2 fi echo "Added user $USER ($COMMENTS) with pass $PASSWORD" } ## Main script starts here adduser bob letmein Bob Holness from Blockbusters if [ "$?" -eq "1" ]; then echo "Something went wrong with useradd" elif [ "$?" -eq "2" ]; then echo "Something went wrong with passwd" else echo "Bob Holness added to the system." fi |