LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash script: Review please (https://www.linuxquestions.org/questions/linux-general-1/bash-script-review-please-192895/)

carmstrong 06-13-2004 12:18 AM

bash script: Review please
 
Hey guys! I'd like to ask if anyone can spot any syntax errors by me in a bash script I wrote. The script is supposed to create a new user account for us. Here goes:

Code:

#!/bin/bash
#parameters: user password sharename
echo "Create: $1" >> newuser.log
/usr/sbin/adduser --shell /bin/false $1 >> newuser.log
chpass() { [[ ! $2 ]] && return 1; { sleep 1; echo $2; sleep 1; echo $2; } passwd $1; }
chpass $1 $2
/bin/mkdir /home/custom/apache2/htdocs/$1 >> newuser.log
/bin/chmod -R 777 /home/custom/apache2/htdocs/$1 >> newuser.log
/bin/mkdir /home/ps/$1
/bin/cp /home/ps/master/* /home/ps/$1
/bin/chmod -R 777 /home/ps/$1
nuu=`cat /etc/passwd |grep $1 | awk -F: '{print $3}'`
/bin/mount --bind -t smbfs //w1/$3 /home/$1/hlds -o username=administrator,password=bah,uid=$nuu >> newuser.log
echo 'mount --bind -t smbfs //w1/$3 /home/$1/hlds -o username=administrator,password=bah,uid=$nuu' >> /etc/init.d/armstrong
/bin/mount --bind /home/$1/web /home/custom/apache2/htdocs/$1 -o uid=$nuu >> newuser.log
echo 'mount --bind /home/$1/web /home/custom/apache2/htdocs/$1 -o uid=$nuu' >> /etc/init.d/armstrong
/bin/mount --bind /home/$1/psychostats /home/ps/$1 -o uid=$nuu >> newuser.log
/home/custom/mysqld-4.0.20/bin/mysqladmin create $1
echo 'grant all on $1.* to $1@localhost identified by '$2';' > temp.sql
/home/custom/mysqld-4.0.20/bin/mysql -u root --password='bah' < ./temp.sql
echo 'mount --bind /home/$1/psychostats /home/ps/$1 -o uid=$nuu' >> /etc/init.d/armstrong
echo "All done! Type cat newuser.log to look for errors, as they've been removed from this output."
echo "Try to login via FTP and verify everything is working."
exit


trickykid 06-13-2004 09:43 AM

Holy crap that is messy to read.. anyway you can edit and clean up, maybe add some spaces, space some of the lines, etc? But how do we know if there are any errors since it appears your mounting shares, etc? Have you tested it yourself, not like it would hurt anything if you did, easily just remove the test user, etc.


All times are GMT -5. The time now is 06:05 PM.