Shell script prompt for first parameter ($1) then run


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script prompt for first parameter ($1) then run
# 1  
Old 03-29-2015
Shell script prompt for first parameter ($1) then run

I have to run post configuration script like this script file is post_config.sh
Code:
post_config.sh 1234    #1234  is node ID


according to given node ID all script run
..
..
But i want to post_config.sh script should ask for node ID then run
like this..

Code:
post_config.sh             #i want to run this file only not with node ID
Enter the node ID here:    #asking for node id here i can put node id like 1234





Eg...
post_config.sh script is like this..
Code:
#This is script for Node Post configuration
#echo "Running script for $1"
 
echo "                      _                             "
echo "                      _                             "
echo "PKG6 Node Post Confg Start.............."
echo "                      _                             "
echo "                      _                             "
 
sleep 5
/home/Nodes/kat/bin/cmd_sys $1 ......
/home/Nodes/kat/bin/cmd_sys $1 ......
/home/Nodes/kat/bin/cmd_sys $1 ......
.
.

Moderator's Comments:
Mod Comment As requested many times before in your posts, please use CODE tags (not ICODE tags), when full lines, and especially when multiple lines, of sample input, output, or code are being displayed.

Last edited by Don Cragun; 03-29-2015 at 05:16 AM.. Reason: Change ICODE tags to CODE tags, again.
# 2  
Old 03-29-2015
You can do something like this
Code:
NodeId=$1
if [ -z "$NodeId" ]; then
  printf "%s" "Enter the node ID here: "
  read NodeId
fi

and then use $NodeId instead of $1 everywhere
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-29-2015
Knowing what shell and operating system you're using could make a big difference here. In addition to what Scrutinizer suggested, maybe something like this will help with your problem:
Code:
#!/bin/ksh
case $# in
(0)	printf 'Enter node number to be processed: '
	read node;;
(1)	node="$1";;
(*)	printf 'Usage: %s [node]\n' "${0##*/}" >&2
	exit 1;;
esac
echo "Running script for node $node."
/home/Nodes/kat/bin/cmd_sys "$node"
... ... ...

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 03-29-2015
Code:
 [ROOT]post_config.sh
Enter node number to be processed: 2459
CONNECT FAIL.
CONNECT FAIL.
CONNECT FAIL.
CONNECT FAIL.

not working......
can any body help..

Last edited by Scrutinizer; 03-29-2015 at 10:19 AM.. Reason: Changed code tags to code tags
# 5  
Old 03-29-2015
Could you post the modified script part that you ended up using....
# 6  
Old 03-29-2015
Not without knowing how the script looks now.
# 7  
Old 03-29-2015
Code:
printf 'Enter node number to be processed: '
read node
node="$node"

echo "Running script for node $node."
/home/Nodes/kat/bin/cmd_sys "$node"

This works
thanks team

Last edited by Scrutinizer; 03-29-2015 at 11:39 AM.. Reason: code tags to code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

4. Homework & Coursework Questions

Shell Script Password Prompt

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to write a shell script that prompts the user for the password which is "lux" once the correct password... (4 Replies)
Discussion started by: Emin_Em
4 Replies

5. Shell Programming and Scripting

Script Shell Parameter

Hi I have two shell script, the second script takes as a parameter the output variable of the first script, please how to retrieve the variable from the first script to pass as a parameter to the second script? Script1.sh i=0 i=$(($i + 1)) Script2.sh echo $1 Thank you (0 Replies)
Discussion started by: chercheur111
0 Replies

6. Shell Programming and Scripting

Help to hide shell terminal and run prompt program after ssh login for specified user

Hey guys, I have some task from my office to lock user on the specified directory after the user logged on using ssh. And then run prompt program to fill the required information. Yeah, just like an ATM system. My question: How could I do those?? AFAIK I have to edit the ~./bashrc. But the... (1 Reply)
Discussion started by: franzramadhan
1 Replies

7. Shell Programming and Scripting

Shell Script to prompt customer for name etc

How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range. Thanks (1 Reply)
Discussion started by: SQLScript
1 Replies

8. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

9. Shell Programming and Scripting

Why Does Command Run From Prompt But Not From Script?

I hope someone can shed any light on this mystery. I am trying to run the following command: su userID -c remsh server -l userid -n "awk -F^ '\$4 == \"SMITH\"' /tmp/infromational/version74b/LIVE/TEMPORARY/ABCfiles/HLC_Database_File.bat|head -1" > /tmp/variant/45BV32/var/store13.logfnd I... (15 Replies)
Discussion started by: Korn0474
15 Replies
Login or Register to Ask a Question