Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ok, i need some help with this bash

Status
Not open for further replies.

w1nn3r

ISP
Sep 12, 2001
179
US
Ok, i need some help with this bash script. Everything runs great until i hit the if else statement then i get this,

Do they want adminmod?
yes
./install_cs: [: yes: integer expression expected
./install_cs: line 29: syntax error near unexpected token `fi'
./install_cs: line 29: ` fi'
root@ds6 [~]#

This is the script, any help would be greatly appreciated.

#!/bin/bash
echo "Welcome to the install script"
sleep 2
echo "What username to add?"
read usern
echo "If your not ROOT this will not work"
adduser $usern
echo "Now you need to type the password for this account"
passwd $usern
sleep 2
echo "How many players?"
read players
cd /home/$usern
sudo -u $usern cp /usr/local/files/hlds_l_3111_full.tar.gz /home/$usern
sudo -u $usern cp /usr/local/files/cs_15_full.tar.gz /home/$usern
sudo -u $usern tar zxvf /home/$usern/hlds_l_3111_full.tar.gz
sudo -u $usern tar zxvf /home/$usern/cs_15_full.tar.gz
echo "Do they want adminmod?"
read adminmod
if [ $adminmod -ne yes ]
then
sudo -u $usern cp /usr/local/files/halflife-admin 2.50.52.tgz /home/$usern
sudo -u $usern tar zxvf /home/$usern/halflife-admin-2.50.52.tgz
cd /home/$usern/Adminmod
sudo -u $usern /home/$usern/Adminmod/install_admin
fi
if [ $adminmod -ne no ]
then
fi
 
-e and -ne are mathmatically sensitive.
You want = or !=.
For this you need to enclose your variable within quotes.
ex:
if ["$adminmod" != "no"] ; then
action
fi
 
thanks marsd, I get a new error when using the script, i've setup the script similar to your example, but get this....

root@ds6 [~]# ./install_cs
Welcome to the install script
What username to add?
sigh
If your not ROOT this will not work
adduser: user sigh exists
Now you need to type the password for this account
Changing password for user sigh.
New password:
BAD PASSWORD: it's WAY too short
Retype new password:
passwd: all authentication tokens updated successfully.
How many players?
12
Do they want adminmod?
Yes
./install_cs: line 50: unexpected EOF while looking for matching `"'
./install_cs: line 53: syntax error: unexpected end of file
root@ds6 [~]#

Any help on this would be greatly appreciated.

----------Script--------------------------------
#!/bin/bash
echo "Welcome to the install script"
sleep 2
echo "What username to add?"
read usern
echo "If your not ROOT this will not work"
adduser $usern
echo "Now you need to type the password for this account"
passwd $usern
sleep 2
echo "How many players?"
read players
cd /home/$usern
sudo -u $usern cp /usr/local/files/hlds_l_3111_full.tar.gz /home/$usern
sudo -u $usern cp /usr/local/files/cs_15_full.tar.gz /home/$usern
sudo -u $usern cp /usr/local/files/psychostats1.9.1.tar.gz /home/$usern
sudo -u $usern tar zxvf /home/$usern/hlds_l_3111_full.tar.gz
sudo -u $usern tar zxvf /home/$usern/cs_15_full.tar.gz
sudo -u $usern tar zxvf /home/$usern/psychostats1.9.1.tar.gz
sudo -u $usern cp -Rf /home/$usern/cstrike /home/$usern/hlds_l
sudo -u $usern rm -rf /home/$usern/cstrike
sudo -u $usern rm -rf /home/$usern/psychostats1.9.1.tar.gz
echo "To correctly install psychostats we need to configure it"
sleep 1
sudo -u $usern pico /home/$usern/psychostats1.9.1/stats.cfg
sleep 2
sudo -u $usern /home/$usern/psychostats1.9.1/install.pl
echo "Do they want adminmod?"
read adminmod
if [ $adminmod = yes ] ; then
sudo -u $usern cp /usr/local/files/halflife-admin-2.50.52.tgz /home/$usern
sudo -u $usern tar zxvf /home/$usern/halflife-admin-2.50.52.tgz
cd /home/$usern/Adminmod
echo &quot;Remember when it asks for your hlds_l dir, use /home/<username>/hlds_l
sudo -u $usern /home/$usern/Adminmod/install_admin
sudo -u $usern rm -rf /home/$usern/Adminmod
elif [ $adminmod = no ] ; then
echo &quot;No adminmod&quot;
fi
echo &quot;Install statsme?&quot;
read statsme
if [ $statsme = yes ] ; then
sudo -u $usern cp /usr/local/files/statsme-2.7.1-cstrike.zip /home/$usern
sudo -u $usern unzip /home/$usern/statsme-2.7.1-cstrike.zip
sudo -u $usern rm -rf /home/$usern/statsme-2.7.1-cstrike.zip
sudo -u $usern cp -Rf /home/$usern/addons/statsme /home/$usern/hlds_l/cstrike/addons
sudo -u $usern rm -rf /home/$usern/addons
sudo -u $usern echo &quot;linux /home/$usern/hlds_l/cstrike/addons/statsme/dlls/sm_cstrike_mm_i386.so&quot; > /home/$usern/hld$
elif [ $statsme = no ] ; then
echo &quot;No statsme&quot;
fi
 
Ignore that, forgot the close &quot; on the line below...

echo &quot;Remember when it asks for your hlds_l dir, use /home/<username>/hlds_l
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top