How can I fetch few parameters in Shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I fetch few parameters in Shell script?
# 1  
Old 07-23-2014
Question How can I fetch few parameters in Shell script?

Hi All,

I want to fetch few details out of a huge output of AWS CLI tools :



I am using this command :
Code:
ec2-describe-instances


Last edited by Palak Sharma; 08-14-2014 at 05:33 PM..
# 2  
Old 07-23-2014
Replace the above awk with below
Code:
awk -F "\t" 'BEGIN{print "INSTANCE ID\tINSTANCE TYPE"} /INSTANCE/ {print $2 "\t" $7}'

---------- Post updated at 04:04 AM ---------- Previous update was at 04:01 AM ----------

Code:
ec2-describe-instances | awk -F "\t" 'BEGIN{print "INSTANCE ID\tINSTANCE TYPE"} /INSTANCE/ {print $2 "\t" $7}'

# 3  
Old 07-23-2014
The output I am getting from your command is :


Code:
INSTANCE ID	INSTANCE TYPE
i-c		cloud
i-6		cloud
i-c		pub


Instead of picking up the instance type its picking up the keys
# 4  
Old 07-23-2014
Code:
ec2-describe-instances | awk -F "\t" 'BEGIN{print "INSTANCE ID\tINSTANCE TYPE"} /INSTANCE/ {print $2 "\t" $9}'

This User Gave Thanks to SriniShoo For This Post:
# 5  
Old 07-23-2014
Thanks a bunch Smilie can you help me further.

I have stored the output in a file called
Code:
Instances

The instances file has this detail:


Code:
INSTANCE ID         INSTANCE TYPE        INSTANCE STATE
i-8					t1.micro			  running
i-5					m3.medium			  running
i-b					m3.large			  running
i-e					m3.medium			  running
i-3					t1.micro			  running

I want to have a check that if the instance type is not t1.micro or t2.micro and the state is running then it should stop the instances with command
Code:
 ec2-stop-instances  instance id


How can I implement this ?
# 6  
Old 07-23-2014
Code:
awk -F "\t" 'NR > 1{if($2 != "t1.micro" && $2 != "t2.micro" && $3 == "running") print $1}' Instances | while read line
do
  ec2-stop-instances "${line}"
done

---------- Post updated at 06:28 AM ---------- Previous update was at 06:25 AM ----------

or
Code:
awk -F "\t" 'NR > 1{if($2 != "t1.micro" && $2 != "t2.micro" && $3 == "running") system("ec2-stop-instances " $1)}' Instances

This User Gave Thanks to SriniShoo For This Post:
# 7  
Old 07-23-2014
It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to fetch values in csv

I need to fetch below values from this file. (1 Reply)
Discussion started by: nit42
1 Replies

2. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. Shell Programming and Scripting

Fetch the latest filename shell script

Hi I want to fetch the latest file form the list example example= filename RATE_STATE_SETUPS.20151222.ccyymmdd.hhmmss.txt File pick which have latest ccyymmdd.hhmmss list of file in directory are RATE_STATE_SETUPS.20151222.20151222.170101.txt... (5 Replies)
Discussion started by: MOHANP12
5 Replies

4. Programming

csh: Parameters in Shell Script Help

I have a program that is designed to take the first parameter (a file extension) and use it to rewrite the file stored in the second paramerter with the new extension. And if the current file does not exist then the program will print an error message "No such file." For example, my program is... (1 Reply)
Discussion started by: Marhsall34
1 Replies

5. UNIX for Dummies Questions & Answers

shell script with parameters?

hi , I wanted to create a script, and I have no idea how to, and I would appreciate any help on that. Any advice on solving this is welcome. Thanks Here it goes: make a shell script in bash that show the activity of users. The results should be a summary or a complete report in a file.... (2 Replies)
Discussion started by: ubu-user
2 Replies

6. Shell Programming and Scripting

call another shell script and pass parameters to that shell script

Hi, I basically have 2 shell scripts. One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system. Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn. ... (2 Replies)
Discussion started by: sunrexstar
2 Replies

7. Shell Programming and Scripting

How to fetch data from oracle in unix shell script

Hi, How to fetch data from oracle database in unix shell scripting. list=`sqlplus -s ds_user/dsuser@EMI <<EOF set feedback off set serveroutput on set heading off set pagesize 0 set tab off select IP_ID from table / exit EOF` The output is not what i expected.I need output in... (4 Replies)
Discussion started by: Anusha_Reddy
4 Replies

8. Shell Programming and Scripting

fetch hostname and instance name using shell script

Hi All, Requirement is to fetch hostname and instance name using shell script from all configuration files on a server R12 on IBM AIX... could anyone please share such an experience encountered before.Is there such a script available in this forum or any other site.. Thanks for your time!... (0 Replies)
Discussion started by: a1_win
0 Replies

9. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies

10. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies
Login or Register to Ask a Question