Page 1 of 1
Schell scripting conditional/directive
Posted: Fri Nov 21, 2008 2:27 am
by alex.barylski
I'm trying to write a shell script which I can run each time I format or upgrade/change remote servers...while I pretty much have the commands all working I'd like to perform some basic conditionals...
Such as checking if the setup is local server and installing things like sloccount which I do not want installed on a remote server.
Is there any way to detect using shell/bash to see if the server is my local server?
Perhaps using a CLI switch?
Also...how do I make the stupid script execute without calling bash like above, just setup?
chmod +x setup I have tried to no avail.
Cheers,
Alex
Re: Schell scripting conditional/directive
Posted: Fri Nov 21, 2008 5:57 am
by VladSun
PCSpectra wrote:Also...how do I make the stupid script execute without calling bash like above, just setup?
chmod +x setup I have tried to no avail.

You need to make it executable and to have a
shebang line at the top of the file.
Sorry, but I didn't get the idea of the rest of your post.
Re: Schell scripting conditional/directive
Posted: Fri Nov 21, 2008 2:26 pm
by alex.barylski
Hmmm...I did have the shebang line...maybe it was pointing at the wrong place...
Re: Schell scripting conditional/directive
Posted: Fri Nov 21, 2008 4:33 pm
by VladSun

Could you show me the output of:
and the exact command you are trying to run your script with together with any output (even errors)?
Re: Schell scripting conditional/directive
Posted: Sat Nov 22, 2008 8:03 am
by alex.barylski
I'm not sure what I'm doing wrong but so long as the shebang line is there and the chood x+ filename it should work?
As for the conditionals...I'm basically trying to automate the process of setting up my server the way I needed it done...
I would like to use conditionals though for case where I am setting up local servers (in which case ssh is requierd to be installed and phpMyAdmin is a likely hood as well).
Something like:
Code: Select all
apt-get install php5 php5-cli php5-curl php5-imap php5-mcrypt apache2 mysql-server
$IF %args == local
apt-get install phpmyadmin ssh
$FI
a2enmod rewrite php5
$IF %args == remote
echo "IMPORTANT: Remember to turn off error reporting"
Basically i want to begin recording the steps I need to take to configure a server to my requirements and ideally I eventually get it so it's entirely automatic so when I need to switch hosts or upgrade I simply invoke a shell script and then upload my PHP files, etc.
I think I just need to read up on bash scripting a little more as I cannot ese it being that difficult to check a command line argument...the syntax is just so damn cryptic. Feels like Perl.
Cheers,
Alex
Re: Schell scripting conditional/directive
Posted: Sat Nov 22, 2008 3:28 pm
by VladSun
PCSpectra wrote:I'm not sure what I'm doing wrong but so long as the shebang line is there and the chood x+ filename it should work?
You didn't paste the output I requested
PCSpectra wrote:I think I just need to read up on bash scripting a little more as I cannot ese it being that difficult to check a command line argument...the syntax is just so damn cryptic. Feels like Perl.

http://tldp.org/LDP/abs/html/ 
LOL, Perl has far much more "damn cryptic" look like
