Thomasttw Thomasttw - 4 years ago 260
Bash Question

My sh codes don't work, help needed

I'm learning to work with linux but it isn't working out

Script 1, did work until I updated opensuse:

#!/bin/bash
useradd Test
passwd Test123
mkhomedir_helper Test


(It now says that all these commands don't exist)

Script 2, I can only get into my MySql console and he doesn't execute everything:

#!/bin/bash
mysql -u root -ppassword
sleep 3
CREATE USER 'Test'@'localhost' IDENTIFIED BY 'password'


I would really appreciate some help here since I'm new to linux

Answer Source

Run following cmd:

echo $PATH

Output should be list some paths as below

/Usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

If not then run below command:

export PATH="/Usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

Now try running above script-1, if it still gives same error, then you are missing some packages, install 'pam' package which contains mkhomedir_helper binaries, so run following command to install pam.

zypper in pam

Script 2, to run mysql query from command line or as a shell script you need to use '-e' option, change the script 2 as below:

#!/bin/bash
mysql -u root -ppassword -e 'CREATE USER "Test"@"localhost" IDENTIFIED BY "password"'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download