Need help to make a shell script with usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to make a shell script with usage
# 1  
Old 12-13-2012
Need help to make a shell script with usage

Hello,

I begin to write my first shell script, but I am totally lost, hope you can help me.

I'd like to write a script with some conditions and multiples usages:
Code:
./myscript.sh -i <host>

or
Code:
./myscript.sh -e <host>

Have you some suggestion, because I am really lost, I try to do something with an echo and a read answer but it is not good.

If you have a good exemple I can adapt it's a good thing for me too.

Last edited by Franklin52; 12-14-2012 at 03:32 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-13-2012
With no indication of what conditions you are talking about, no indication of what you want the -i and -e options to do, and no indication of what you want the script to do with or without options; it is hard to make any useful suggestions.
# 3  
Old 12-13-2012
Passing parameters

Take a look at this post, where it shows parameters being passed.
https://www.unix.com/shell-programmin...rs-spaces.html
# 4  
Old 12-13-2012
Francesco, can you briefly explain what is your requirement?
# 5  
Old 12-13-2012
you just need to search for
Code:
CASE

statement on google. I hope this is what you are looking for.
# 6  
Old 12-13-2012
I must admit I am not very clear, please excuse me.

myscript.sh has differents usage
Code:
./myscript.sh -i <host>

==> will lauch an apt-get update on <$host>

Code:
./myscript.sh -e <host>

==> will launch an apt-get remove on <$host>

I have 6 hosts=
Code:
HOST='host1 host2 host3 host4 host5 host6'

I'd like to use fonction to execute the command, but all the exemple I saw are not very easy for me.

I'd like to have an usage:
Code:
./myscript.sh
Usage: myscript.sh {install -i host|remove -e host|}

Regards,

Last edited by Franklin52; 12-14-2012 at 03:32 AM.. Reason: Please use code tags for data and code samples
# 7  
Old 12-13-2012
Code:
if [ "$#" -eq 0 ]
then
        echo "Usage: myscript.sh {install -i host|remove -e host|}"
        exit 1
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell script that monitors CPU Usage

I'm a newbie to shell scripting, I was given this script to modify. This script that monitors when CPU Usage is too high based off the top command. The comparison is not working as it should. Its comparing a decimal to a regualar interger. When it send me an email, it send an email and ignores the... (21 Replies)
Discussion started by: mhannor
21 Replies

2. UNIX for Dummies Questions & Answers

Basic sed usage in shell script

Hi, A basic sed question. I have a set of files. In each file there is a number that I want replaced. For example, if I run sed I should get the following: % cat test2.txt #goofy//171.00 goofy 171.00 % sed -i 's/171/xxx/g' test2.txt % cat test2.txt #goofy//xxx.00 goofy xxx.00 ... (2 Replies)
Discussion started by: pc2001
2 Replies

3. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

4. Shell Programming and Scripting

Pattern extraction and usage by shell script

Suppose im in a directory A. which has sub-directories x/y/z m/n/p etc. Iam only considered with those which have a file netl.oa at the lowermost level. So i used the find command which gives me a list in the form ./abc/def/ghi/jkl/netl.oa and so on Now i want the names abc def jkl and ghi. My... (3 Replies)
Discussion started by: sid.verycool
3 Replies

5. Shell Programming and Scripting

Need help on ssh usage in a loop of shell script

I need help on how to connect remote systems through ssh command in while loop of shell script. I was able to connect one remote system using ssh from shell script. Please find sample code snippet as given below….. ssh "root@148.147.179.100" ARG1=$rpmFileName 'bash -s' <<'ENDSSH' ... (5 Replies)
Discussion started by: rajesh.tulluri
5 Replies

6. Shell Programming and Scripting

argv usage in a korn shell script

I'm trying to count and display the variables on a command line #!/bin/ksh $# argv from command line: tryit2 this is a test returns : tryit2: 4: not found. (1 Reply)
Discussion started by: Bperl1967
1 Replies

7. Shell Programming and Scripting

usage of telnet in shell script

Hi All, How could I use telnet to connect to Primary Host in the below shell script: Could I use: ( echo user sleep 2 echo password sleep 2 echo "ls ~" sleep 2 echo "exit" ) | telnet hostname ... (1 Reply)
Discussion started by: a1_win
1 Replies

8. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

9. Shell Programming and Scripting

how do i get current bandwidth usage via shell script?

hello unix-people. can u please tell me how i can get the current bandwidth usage of my machine on shell into variables? thanks a lot (2 Replies)
Discussion started by: scarfake
2 Replies

10. UNIX for Dummies Questions & Answers

shell script extended usage...

Hi all, In a shell script, how can I do the following: Find out the size of a mounted usb stick (df -h /media/usbdisk) and use the result (physical size of USB stick) to set a loop-counter according to the disk size?? As a result, I do copy files of 4MB each as many times as they will fit... (1 Reply)
Discussion started by: joerg535
1 Replies
Login or Register to Ask a Question