Schell scripting conditional/directive

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Schell scripting conditional/directive

Post 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?

Code: Select all

bash setup --local
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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Schell scripting conditional/directive

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Schell scripting conditional/directive

Post by alex.barylski »

Hmmm...I did have the shebang line...maybe it was pointing at the wrong place...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Schell scripting conditional/directive

Post by VladSun »

:)
Could you show me the output of:

Code: Select all

head your_script file

Code: Select all

ls -l your_script file
and the exact command you are trying to run your script with together with any output (even errors)?
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Schell scripting conditional/directive

Post 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. :P

Cheers,
Alex
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Schell scripting conditional/directive

Post 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. :P
http://tldp.org/LDP/abs/html/ ;)
LOL, Perl has far much more "damn cryptic" look like :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply