0

I have a problem to write script for checking server. Anyway my script sticks on "shell" line of code.

When I execute command "shell" inside of script, it won't go further to other command. so basically look like this:

#!/bin/sh
#exec > output.txt

echo -en '\n'
echo -en '\n'
echo "-------------------------- Daily Check Script ------------------------------"
echo "                                                                      MYteam"
echo -en '\n'
echo "CHECK MASTER/SLAVE node----------------------------------------------------"
echo -en '\n'

var="$(hbmode status )"

if [[ $var =~ "M_WITH_S / S_WITH_M" ]]; then
    echo "You are on MASTER node"
else
    echo "You are on SLAVE node"
fi

current_date=$(date)

echo -en '\n'
echo "Today is ---------------------------------------------------------------"
#echo -en '\n'
echo "Today is $current_date"
echo -en '\n'
echo "Checking SERVER VIP active-----------------------------------------"

shell 

After "shell" command, I get this:

Local controller version is 3.0.0
 Usage : Type <tab> or help for commands and completion.

server1.it.sunburning.gr>

I need to type command: vdip route show but script won't execute this command.

How can I inside of script execute shell and vdip route show command, and exit from shell afterwards to execute other commands like , df -h, free -m etc....

I want to use this script in Cron.

jhnc
  • 11,310
  • 1
  • 9
  • 26
hippietech
  • 11
  • 1
  • 2
    what does `shell` command do ? You need **interactive shell**? – Shakiba Moshiri Jul 26 '22 at 13:29
  • `expect` [(tcl)](https://core.tcl-lang.org/expect/index)[(wikipedia)](https://en.wikipedia.org/wiki/Expect) is designed for this sort of thing. or you may be able to just redirect input to `shell` from a file or heredoc – jhnc Jul 26 '22 at 13:41
  • Hi there, well shell command do nothing, just set environment for command "vdip route show" .. so lets say YES it need to be interactive and i need after "vdip route show" command to exit shell to continue with script commands like (df -h, free -m.. etc) Thank you. – hippietech Jul 26 '22 at 13:42
  • 1
    Please [edit] your question to provide requested information, don't use comments for this purpose. How do you exit from the `shell` command? Do you have to type a command like `exit` or `quit`? Do you press CTRL+D? Did you try `echo vdip route show | shell`? – Bodo Jul 26 '22 at 13:49
  • Tnx Bodo "echo vdip route show | shell" This works <3 – hippietech Jul 26 '22 at 13:51
  • `expect` is overused. Prefer providing information needed by a command via command-line arguments or standard input before trying to interact with the running command. – chepner Jul 26 '22 at 13:56

0 Answers0