1

I have to connect to a different cli and execute few commands and exit. sudo $SIGNMCLI connects to a cli. The below script doesn't work. I want to execute the exit in SIGNMCLI.

#!/bin/bash -xv

SIGNMCLI=/opt/sign/EABss7024/bin/signmcli

if [ -f "$FileCheck" ];
then
        sudo $SIGNMCLI
        exit;
fi

If I do the following, it works:

#!/bin/bash -xv

SIGNMCLI=/opt/sign/EABss7024/bin/signmcli

if [ -f "$FileCheck" ];
then
        echo 'exit' |sudo  $SIGNMCLI
fi

But, I want to execute multiple commands in SIGNMCLI. Is there anyway to redirect the control to SIGNMCLI and after executing all the commands, the control comes back?

1
  • SIGNMCLI=/opt/sign/EABss7024/bin/signmcli Commented Apr 7, 2017 at 7:35

1 Answer 1

1

You can execute multiple commands using semicolon operator in your script.

cmd1 ; cmd2 ; cmd3 ...

In you case, I suggest you to use ; or &.

    echo 'exit'; sudo  $SIGNMCLI

This is the basic usage of commands.

* A; B    Run A and then B, regardless of success of A
* A && B  Run B if A succeeded
* A || B  Run B if A failed
* A &     Run A in background.
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thanks for reply, I tried its working. echo 'ls;ifconfig;who;exit'|sudo $SIGNMCLI apart from this any other command is there. without using 'echo' command normally shell script if we are processing any ORACLE request means we are using >> EOF ....... EOF same like any commands are there in shell
Hi, i have one more doubt, using shells script i need to continuously checks the directory for particular file, if the particular file is present i need to do some operation. eg: if file present i need to restart stack 'ss7-stack restart'
You didnt even upvoted for the provided solution. And now your asking for another shell issue, raise another questions in sf.
The previous solution is working fine. if [ -f "$FileCheck" ]; then echo "$FileCheck found entering signmcli command." echo '$SIGNMCLI_RESTART;exit' | sudo $SIGNMCLI else echo "$FileCheck not found." >&2 fi
If it works fine means you can upvote that's the least courtesy you can do. You can click the mouse button up on little triangle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.