script with more then one switch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script with more then one switch
# 1  
Old 08-29-2007
script with more then one switch

Hi, have managed to code a script that has a simple menu so for instance if I run:

Quote:
./theprogram.sh -h
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 functionality for more then one switch on the same line!

this is what i mean:

Quote:
./theprogram.sh -f acces.log -s ip
In the above the program has two switches -f is file so the program knows where the file is which is access.log and -s is the sort option and I want it to sort the access.log file by ip

Basically the program essentially modifys how a squid log file looks , so for eg you can list the log from a-z based on hostname would be one functionality.

Any ideas? I am really stuck.
# 2  
Old 08-29-2007
kinda worked it out using $1 $2 etc.
# 3  
Old 08-29-2007
You should use getopts if you are planning to handle a lot of arguments. It will make things a lot easier.
# 4  
Old 08-29-2007
YOu can code is it using the function GETOPTS and OPTARGS. GETOPTS will check for the flags, and OPTARGS will get the arguments for that flags.

Last edited by ahmedwaseem2000; 08-29-2007 at 03:53 AM..
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

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... (3 Replies)
Discussion started by: atanubanerji
3 Replies

3. 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

4. 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

5. 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

6. 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

7. 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

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

switch user inside a script

Hi Is there any way to switch user inside a shell script? (4 Replies)
Discussion started by: ./hari.sh
4 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