Using commands within bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using commands within bash script
# 1  
Old 08-22-2018
Using commands within bash script

The purpose of enclosed script is to execute selected command and output success or failure in whiptail msgBox

Works as expected when command returns zero to msgBox.


I cannot figure out how to continue / automate my script when command expects reply to continue / terminate. I am doing it manually in terminal by keying "q".


Basically

how do I detect in my script that the command requires response continue / return "control " back to scrip

and how do I insert "q" into my script?




PS I have deleted commented out code so the line numbers are NOT is sequence.




Code:

                         while read choice
  199  do
 204  $choice  #execute command  
 211 exitstatus=$?
 212  if [ $exitstatus = 0 ]; then
         msgDialog
  220 ((counter++))
  221  else
  222         echo "Exit status failed "
        fi

232  done < results


Last edited by annacreek; 08-22-2018 at 10:20 PM..
# 2  
Old 08-22-2018
The break command is used to leave a loop eg:

Code:
while read choice
do
  $choice  #execute command  
  exitstatus=$?
  if [ $exitstatus = 0 ]; then
         msgDialog
        ((counter++))
  else
      echo "Exit status failed "
      break  # Leave the while loop
  fi
done < results

# Execution will resume here if end of results file reached or break statement above is triggered

# 3  
Old 08-22-2018
I am sorry, that is not what I asked for.
Maybe this will clarify my request.

Here is a sample of one of the command outputs currently send to terminal and to get back to my script I have to use keyboard and type "q".
I would like to "automate" this outwit user interaction.




Code:
pi
    State: degraded
     Jobs: 0 queued
   Failed: 2 units
    Since: Thu 1970-01-01 00:00:01 UTC; 48 years 7 months ago
   CGroup: /
           |-user.slice
           | `-user-1000.slice
           |   |-user@1000.service
           |   | |-gvfs-gphoto2-volume-monitor.service
           |   | | `-808 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
           |   | |-dbus.service
           |   | | `-669 /usr/bin/dbus-daemon --session --address=systemd: --nof
           |   | |-gvfs-udisks2-volume-monitor.service
           |   | | `-789 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
           |   | |-gvfs-mtp-volume-monitor.service
           |   | | `-828 /usr/lib/gvfs/gvfs-mtp-volume-monitor
           |   | |-gvfs-goa-volume-monitor.service
           |   | | `-824 /usr/lib/gvfs/gvfs-goa-volume-monitor
           |   | |-gvfs-afc-volume-monitor.service
           |   | | `-803 /usr/lib/gvfs/gvfs-afc-volume-monitor
           |   | |-init.scope
           |   | | |-652 /lib/systemd/systemd --user
lines 1-23


I am currently trying to redirect the command output back to my scrip and maybe I won't need this keyboard interaction.

------ Post updated at 09:41 PM ------

Here is the solution , outputs the entire file to "script window ", text can be scrolled and the display can be terminated using standard "buttons"



Code:
inputBox(){
  37  HOSTNAME=$(\
  38  whiptail \
  39  --scrolltext \
  40  --title "Test input /text box " \
  41  --textbox /dev/stdin 20 80 <<<$($choice) \
  42 3>&1 1>&2 2>&3)
  43  
  44 }


Last edited by MadeInGermany; 08-23-2018 at 03:44 AM.. Reason: Corrected code tag
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^ / { print $1 } /^:+ / { print $1 " ACCEPT" ; } /COMMIT/ { print $0; }' | iptables-restoreMy first attempt at bash... (9 Replies)
Discussion started by: thixeqi
9 Replies

3. Shell Programming and Scripting

Why commands inside bash script lost effectiveness?

Hi, I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment. For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel"... (4 Replies)
Discussion started by: hce
4 Replies

4. Shell Programming and Scripting

Combine several commands in a bash script

Hi all, I have large files with url-s ending on "|<number>" which is the Page Rank for the website as shown in the example below http://www.machinokairo.com/2012/05/post-39.html|2 I am using "grep" to sort out all url-s in a particular way: first, remove all ending on "|0" and write the... (9 Replies)
Discussion started by: georgi58
9 Replies

5. Shell Programming and Scripting

How to combine awk and bash commands in script ?

Dear friends, I am just trying write one script using 2 files one file will contain details like below #X SERVER X LOCATION URL="http://www.abcd.com" FILENAME="abc.txt" ID_NAME="myabc_xyz" SERVER_PATH="/usr/local/dummy/html/....." #Y SERVER Y LOCATION URL="http://www.xyz.com"... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

6. Shell Programming and Scripting

Suppressing the terminated message from pkill & killall commands in a bash script

Hi all, I've been pulling my hair out with this problem for 3 days:wall: now without success any help would be massively appreciated. Basically the script is used to shutdown a rails server so a new IP address can be assigned, the shutdown part is taken care of in function_one using the... (2 Replies)
Discussion started by: danmc
2 Replies

7. Shell Programming and Scripting

Execute ssh commands through bash script

Hi all! I am trying to write a script that will check if a certain directory is available at several different nodes and then do stuff in it ..... On the beginning of the script I give as a variable the directory and the number of the nodes and then I loop like this: for... (3 Replies)
Discussion started by: idet2
3 Replies

8. Shell Programming and Scripting

how to run non-standard commands in bash script?

Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you. I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by... (12 Replies)
Discussion started by: EinsteinMcfly
12 Replies

9. Shell Programming and Scripting

Execute commands from script in current bash session

I have a file as follows: cat /etc/mxg/ssh-hostsmx.example1.com.au:2225 mx2.example2.com.au:2225 mx.example3.com.au:2225 mail.example4.com.au:2225 mail.example5.org.au:2225 mail.example6.com.au:2225I want to dynamically create aliases for quick access to these servers from bash. I wrote... (4 Replies)
Discussion started by: jelloir
4 Replies

10. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies
Login or Register to Ask a Question