Script to execute with switch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to execute with switch
# 1  
Old 07-08-2015
Script to execute with switch

Hello
I want to create a script which will require a mandatory value and optional values which can be supplied using switch. If optional values are not supplied, the script will use the default values mentioned in the script.

For example, how we create user in linux systems.

Please help/guide.
# 2  
Old 07-08-2015
Is this homework ?

Any effort from your side ?

Regards
Peasant.
# 3  
Old 07-08-2015
Hello Peasant

Actually I was searching the easiest way to get the job done....some thing like ..
Code:
sh myscript.sh <dir_name> -w <value> -c <value>

Where <dir_name> is mandatory, and values supplied with -w or -c is optional. If optional values are not supplied, default value will be taken.

Last edited by rbatte1; 07-08-2015 at 01:17 PM.. Reason: Changed ICODE tags to CODE tags
# 4  
Old 07-08-2015
Looks like a job for getops with OPTIND check for default (no options).

You might want to take a look at the examples search engine provides.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to switch user in shell script?

HI in a server we can't login with root user directly but i can login with different user and then i can switch to root user by su command Requirement is there anyway where i can write a script without mentioning password in file as mentioning the root password is not the... (3 Replies)
Discussion started by: scriptor
3 Replies

2. Shell Programming and Scripting

Switch between root and user in the same script.

I am writing a korn shell script where i need to switch to root in between and again exit from root to normal user and continue other commands. Is that possible to switch between these two in the same script? (1 Reply)
Discussion started by: santosh2626
1 Replies

3. Shell Programming and Scripting

using expect to switch users in a script

hi, I need to switch users in a script I'm newbee to expect I wrote two files 1 sudo.exp, since su4098 is used as root in my laptop #!/usr/bin/expect spawn su su4098 expect *Password:* send mypsw\n interact 2 test.sh ls ./sudo.exp tcpdump -i wlan0 su esolve ls however, in... (1 Reply)
Discussion started by: esolve
1 Replies

4. UNIX for Advanced & Expert Users

Help with server switch shell script

I need a script to change server automatically after performing some operations. The command for changing server is ssh username@servername . Then a prompt comes to enter a password. Then i need to perform some opertaions on the other server. How can i do this in a script? (1 Reply)
Discussion started by: pratikm23
1 Replies

5. Shell Programming and Scripting

How to switch user using shell script ?

Hi, script1.sh script2.sh script3.sh From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post... (1 Reply)
Discussion started by: milink
1 Replies

6. Shell Programming and Scripting

Switch User in within a Shell Script

Hi Experts, I'm trying to write a shell script to stop few things where i have to use another user to execute a command. Otherwise it will not work. Your help is really appreciated Thanks, (16 Replies)
Discussion started by: Afi_Linux
16 Replies

7. Shell Programming and Scripting

Switch from one database to other using shell script

Hi all, This is my first ever post to any forum so, dont let this go in vain...........:) Here is the scenario........ I have logged into the unix where oracle_sid is initialized for some X database in the .profile. I have a unix script where some sql query which fetches data from X... (3 Replies)
Discussion started by: sachinkl
3 Replies

8. Shell Programming and Scripting

Making a Script with switch as option

Hi all, I want to make a script which should be able to use switch, eg. If i want to perform a operation on a single file , i should give file path as argument i.e. SCRIPT <PATH> Now if i want to perform the same operation on a bunch of files, i should write as SCRIPT -f filename where... (2 Replies)
Discussion started by: sarbjit
2 Replies

9. Shell Programming and Scripting

script with more then one switch

Hi, have managed to code a script that has a simple menu so for instance if I run: this will call a help function that displays the programs help, I have coded this in using a case statement so if: case is h) call the help function The problem is I don't know how to code in the... (3 Replies)
Discussion started by: Del33t
3 Replies

10. Shell Programming and Scripting

switch user inside a script

Hi, I wrote a unix script that will perform differnt tasks on bahalf of number of users. I use "sudo" to run the script. The problem is when I execute the command: su - user -c "xxx " > output_file, I get the system output header frm the su command. Is there a way to get rid of it instdead of... (2 Replies)
Discussion started by: nimo
2 Replies
Login or Register to Ask a Question