Useradd command not found in expect shebang


#1

Hi Team,

I am using shell script to add user and update password automatically.Below is my shell script.

#!/usr/bin/expect

set timeout 120

useradd rock

spawn passwd rock

expect {
“Enter new UNIX password:” { send “rock@123\r” }
}

expect eof

When i run that script its throwing an error.

[root@WEBPORTALSEA ~]# ./user.sh

invalid command name “useradd”

while executing "useradd rock"

(file "./user.sh" line 3)

Please let us know how to resolve. I am using RHEL 6.8 Version


#2
#!/bin/bash
echo 'Digite o nome do usuário:'
read user

if [ -n "$user" ]; then
	adduser $user
fi

#3

Hi

Thanks for your reply. May i know the meaning of -n “$user” exactly what this command will do

Regards
Arunk


#4

Actually it is not a command is only a check if the variable “$user” has some value avoiding mistakes when you run the command “adduser”