How to write if condition in shell script for application server?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to write if condition in shell script for application server?
# 1  
Old 01-19-2016
Display How to write if condition in shell script for application server?

Hi all,

I have a code to create folder in application server through shell script and i want to create if conditional based folder

Code:
folder=$HOME/test/sample/whatever  
  
if [ -d "$folder" ]; then  
  echo "$folder already exists, not created."  
else  
  mkdir -p "$folder" > /dev/null 2>&1  
  status=$?  
  if [ "$status" -eq 0 ]; then  
    echo "$folder created"  
  else  
    echo "Error creating $folder"  
  fi  
fi


so now i want to write if condition like,

Code:
if country='US'  then create folder=$HOME/test/sample
 
if country='NON-US' then   create folder=$HOME/test/sample/EMPNO

How to impalement within the above code

Thanks

Last edited by Don Cragun; 01-19-2016 at 02:07 AM.. Reason: Add CODE tags.
# 2  
Old 01-19-2016
Is this a homework assignment? Homework and coursework questions can only be posted in the Homework and coursework forum and must include a completely filled out questionnaire from the special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If this is not homework, please explain why you were able to write nested if-then-else statements in the code you have shown us, but you are not able to write another if statement now.
# 3  
Old 01-19-2016
Thanks.

I want to create a folders if the country is US then $HOME/test/sample

and if counntry is non-us so then, create folder as $HOME/test/sample/EMPNO

Please suggest , really i am new to this topic
# 4  
Old 01-19-2016
You didn't answer the homework question.

Do you understand how your code snippet and its elements work?
# 5  
Old 01-19-2016
By the way, this:
Quote:
Originally Posted by Boost
Code:
  mkdir -p "$folder" > /dev/null 2>&1  
  status=$?  
  if [ "$status" -eq 0 ]; then

is nonsense. You will still have to answer Don's question to find out why.

bakunin
This User Gave Thanks to bakunin For This Post:
# 6  
Old 01-29-2016
Hi all,

Sorry for delay.
I want to create folder=$HOME/test/sample(exists) folders , now i want to add
/HOME/test/sample/Whatever ...here whatever need to take from select statement.

i don't want to write if conditions.
Could you please help me.
# 7  
Old 01-29-2016
Hello Boost,

There are few points here.

I- First of all you should reply to the questions asked by Moderators/admins/advisors/members. So by doing this it shows you are taking this conversation seriously and really willing to learn/help here. Which you haven't replied as of now.

II- You should code tags as per forum rules for commands/codes/Inputs which you are using into your posts.

III- Go through the HOME page here for all the forums and decide wisely that your question could suite which sub forum. Like this case it shouldn't come to UNIX for Advanced & Expert Users(Until you reply our questions and make us feel, your questions should be in this forum).

Hope this helps.

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

4. Shell Programming and Scripting

How to write a shell script for rsync to remote server?

Hello, Can you help me to write a shell script for rsync a folder from my server to remote server ? i do this in ssh by this command : rsync -avz -e ssh /copy/me/ login@serverip:/where/to i want have a shell script that do this command. and you know that this command ask remote... (0 Replies)
Discussion started by: Desperados
0 Replies

5. Programming

How to write a shell script to connect to another server?

Hello friends I want to write a script in which I will connect to my friends network. I want to use SSH. Even they can use the script to log into my network and copy files. ssh user@hostname command I know the following command will help me to log into Google's servers and see all the... (12 Replies)
Discussion started by: Angelo
12 Replies

6. Programming

To write C Script for connecting to a Server

Hi, I am little bit new to this scripting langauge as such, though I know the basics. I want to write a C script which connect to a server which is listening on tcp/ip via port number 6901 with username and password and then i have to call various services to test the server. Can some one help... (7 Replies)
Discussion started by: Nagesh
7 Replies

7. Shell Programming and Scripting

How to write a script by using unix commands to down any server

Hi, I need to do frequently server down and up. Every time i am using nearly 5 to 6 commands to down and agin i am using the commands to up. Can anybody help me to write a script to down and up. which i can use once on unix platform it can down later it can up the server. (1 Reply)
Discussion started by: sreerao
1 Replies

8. UNIX for Advanced & Expert Users

which port to write my server application?

I want to write a server application that would accept HTTP requests from client. The server would be on a machine that has no connection to the INTERNET. The clients that would be posting their HTTP requests would be doing so through webbrowser .Thus it would be sort of intranet application.... (0 Replies)
Discussion started by: rraajjiibb
0 Replies

9. Shell Programming and Scripting

run a application from a remote server via script?

I have a ksh script that does a bunch of things, then runs telnet server_b I then manually login, manually run one command (which launches an application with display back to my workstation), then logout at which point the main script takes back over, runs something else, then ends. Is... (4 Replies)
Discussion started by: yankee428
4 Replies

10. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies
Login or Register to Ask a Question