Interactive script – if then


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interactive script – if then
# 1  
Old 09-22-2010
Interactive script – if then

Hi,

I am writing an interactive shell script (ksh) but I have no idea how I could make a condition on it :


Variables :

Code:
  rep_config="${rep_tools}/_CONFIG"
  rep_config_old="${rep_config}/_PROTO_OLD"

Here is the interactice part :


Code:
  lst_proto=$(cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort)
  lst_proto_old=$(cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort)
   
  echo "$lst_proto : "
  echo " "
  echo "--------OLD PROTOTYPE-------------"
  echo "$lst_proto_old : \c"
   
  read prototype
  echo "-------------------------------------------"
  echo "You have Chosen : $prototype \n"
  echo "-------------------------------------------"
  echo " "

Here is the idea :

The CAT command goes on 2 differents directory and then find inside on all configuation files the name of the data you want to choose. There one directory for the current data and another directory for the old data.


Code:
    DIR1
  IDEFIX.cfg
  "#nom_transfert#" will return IDEFIX
   
              DIR2
              ASTERIX_old.cfg
              "#nom_transfert#" will return ASTERIX

My needs is to create a condition that will say something like this :

If $prototype has been chosen from $ls_proto do this ..... otherwise do this ....

I did try to make something like :



Code:
  cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort> listeprotocfg
  cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort> listeprotocfg_old
   
   
   
  #echo "$lst_proto : "
  echo $(( cat listeprotocfg ))
  echo " "
  echo "--------OLD PROTOTYPE-------------"
  echo " "
  #echo "$lst_proto_old : \c"
  echo $(( cat listeprotocfg_old ))
  read prototype
   
  type_proto=grep ${prototype} listeprotocfg
   
  if type_proto="" then
  # If the PROTYPE IS OLD
  fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
  rep_config="${rep_config}/_PROTO_OLD"
  nom_fichier=grep $prototype $rep_config/*  | awk -F":" '{print $1}'
  else
   
  fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
   
  fi
   
  echo "-------------------------------------------"
  echo "YOU HAVE CHOSEN : $prototype \n"
  echo "-------------------------------------------"
  echo " "

As you can see it is not really good... I hope you will be able to help me to make it right.


Thanks
# 2  
Old 09-22-2010
Maybe something like this (not tested, i haven't any source data)
Code:
cat listeprotocfg   # Simply !
echo   # Simply !
echo "--------OLD PROTOTYPE-------------"
echo   # Simply !
# The 3 lines above can be replaced by :
# echo -e "\n--------OLD PROTOTYPE-------------\n"
cat listeprotocfg_old
read prototype
# type_proto=grep ${prototype} listeprotocfg
# if type_proto=""
# then
if grep $prototype listeprotocfg   # Simply !
then
   fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
   rep_config="${rep_config}/_PROTO_OLD"
   nom_fichier=grep $prototype $rep_config/*  | awk -F":" '{print $1}'
else
   fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
fi
echo "-------------------------------------------"
echo "YOU HAVE CHOSEN : $prototype" # no '\n' needed (like in printf). For use of special characters, yoiu have to use the -e (extended) option of echo
echo "-------------------------------------------"
echo

# 3  
Old 09-22-2010
Hi ,

here is what have done so far ... it's not working yet as i am trouble with the test argument but you maybe could help me on this ... I am not good enought to say i am doing it on the right way ....

Code:
lst_proto=$(cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'| sort)
lst_proto_old=$(cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'| sort)

echo "$lst_proto : "
echo " "
echo "--------OLD PROTOTYPE-------------"
echo " "
echo "$lst_proto_old : \c"

read prototype

echo "-------------------------------------------"
echo "You have chosen : $prototype \n"
echo "-------------------------------------------"
echo " "

#------------------------Prototype version------------------------

type_proto=$( ls * ${rep_config} | grep ${prototype} | grep .cfg )
if [ ${type_proto} = " " ] ;
then

#------------------------Prototype OLD----------------------------
cd ${rep_config_old}
pwd
type_proto=$(ls * | grep ${prototype} | grep .cfg | head -1 )
echo ${type_proto}
tronc_staf=$(cat ${type_proto} | grep "#tronc_staf#" | awk '{print $2}' )
echo $tronc_staf
cat ${type_proto} | grep "#nbr_feuille_par_#branche#" | awk -F" " '{print $2}' > ${fic_tmp_arbo}

else

#------------------------Prototype current------------------------
cd ${rep_config}
pwd
echo ${type_proto}
tronc_staf=$(cat ${type_proto} | grep "#tronc_staf#" | awk '{print $2}' )
echo $tronc_staf
cat ${type_proto} | grep "#nbr_feuille_par_#branche#" | awk -F" " '{print $2}' > ${fic_tmp_arbo}

fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Interactive Shutdown script

Hello folks. I will start out by saying as far as unix/linux scripting goes I know less about it than i do about giving birth (I'm a guy hehe). I am looking to make a shutdown script that will either shut down the system or reboot it using one of the shutdown run methods IE init 2 - 5 or a base... (1 Reply)
Discussion started by: azurie
1 Replies

2. Shell Programming and Scripting

Interactive script with background

I have script, which need some variable from user and i use below command for this read this script works fine while running without background, but when i run this script in background, it ask first variable then immediately it show below error KSH variable not found please let me... (1 Reply)
Discussion started by: pallvi_mahajan
1 Replies

3. Shell Programming and Scripting

Non interactive su in bash script

Hi, I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt? Thank you. (4 Replies)
Discussion started by: hce
4 Replies

4. Shell Programming and Scripting

Crontab and interactive script

Hi all, I'm trying to execute from crontab a script that uses an interactive shell (swmml, Signalware MML Commands). I think the problem is about the crontab environment which miss tty/console/terminal etc... After many tryings and searches I didn't come to a solution. The program is... (13 Replies)
Discussion started by: Evan
13 Replies

5. Shell Programming and Scripting

Interactive script

Greetings gurus I have this simple scripts #!/bin/bash find /kl1/CTT/TQI_001/330_spike/sz00/latcon1/ -type d -name "*.dig" > data_schema find /kl1/CTT/TQI_001/330_spike/sz00/latcon1/ -type d -name "*.dig" >> data_schema <data.schema awk '{print NR, "inVol=" $0, "setDt=4000",... (1 Reply)
Discussion started by: Marjan
1 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

8. Shell Programming and Scripting

Automating Interactive script

I have a script that will install software on all remote host. At the end of the script it starts the install.sh part and goes into a interactive mode asking Yes or No questions and prompting to add a username and password. My question is how can I script this so that these questions are... (7 Replies)
Discussion started by: soupbone38
7 Replies

9. Shell Programming and Scripting

script to non interactive mode

Gud morning everybody, I need small help form you people,Please advice me. I have a utility(adpatch) which takes 10-15 prompts, i want to automate this by calling this utility in shell script. Now my qiestion i want to run the script in non interactive mode. An example. $adpatch... (1 Reply)
Discussion started by: swetham.apps
1 Replies

10. Shell Programming and Scripting

Wrap Interactive Script

Does anyone know of a program to wrap an interactive script into an application..I tried using platypus but i want a utility to allow interactive scripts to be run in a stand-alone window to avoid .profile settings on multiple computers...platypus provides the option of a text window output but... (0 Replies)
Discussion started by: meskue
0 Replies
Login or Register to Ask a Question