Bash script to run command in localized CLI [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite












I'm trying to run a command that access a local switch CLI and runs a simple 'show config'. The script logs in, but then does nothing. I suspect it's because once logged in to the sub-terminal, the commands can't be interpreted. Any ideas?



$a1 = "show config"

exec cli

sleep 2

exec $a1
exec exit






share|improve this question














closed as unclear what you're asking by jasonwryan, G-Man, cas, ilkkachu, GAD3R Feb 1 at 18:27


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
    – Volker Siegel
    Feb 1 at 5:06














up vote
-3
down vote

favorite












I'm trying to run a command that access a local switch CLI and runs a simple 'show config'. The script logs in, but then does nothing. I suspect it's because once logged in to the sub-terminal, the commands can't be interpreted. Any ideas?



$a1 = "show config"

exec cli

sleep 2

exec $a1
exec exit






share|improve this question














closed as unclear what you're asking by jasonwryan, G-Man, cas, ilkkachu, GAD3R Feb 1 at 18:27


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
    – Volker Siegel
    Feb 1 at 5:06












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I'm trying to run a command that access a local switch CLI and runs a simple 'show config'. The script logs in, but then does nothing. I suspect it's because once logged in to the sub-terminal, the commands can't be interpreted. Any ideas?



$a1 = "show config"

exec cli

sleep 2

exec $a1
exec exit






share|improve this question














I'm trying to run a command that access a local switch CLI and runs a simple 'show config'. The script logs in, but then does nothing. I suspect it's because once logged in to the sub-terminal, the commands can't be interpreted. Any ideas?



$a1 = "show config"

exec cli

sleep 2

exec $a1
exec exit








share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 4:55









Hunter.S.Thompson

4,50631334




4,50631334










asked Feb 1 at 4:54









K Enz

1




1




closed as unclear what you're asking by jasonwryan, G-Man, cas, ilkkachu, GAD3R Feb 1 at 18:27


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by jasonwryan, G-Man, cas, ilkkachu, GAD3R Feb 1 at 18:27


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
    – Volker Siegel
    Feb 1 at 5:06












  • 1




    Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
    – Volker Siegel
    Feb 1 at 5:06







1




1




Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
– Volker Siegel
Feb 1 at 5:06




Could you clarify "that access a local switch CLI"? is it about a network switch? Do you use ssh somewhere?
– Volker Siegel
Feb 1 at 5:06










1 Answer
1






active

oldest

votes

















up vote
1
down vote













After exec cli, your shell script does not return to run the next line, sleep 2
To be exact, it no longer exists, because exec replaces the shell process by the new cli process.



I suspect you do not really want the effect of exec, and should remove it.



I am not really sure what you want to do, but assuming you want to run the command show config in cli, try just writing the command to it's input:



printf "show config" | cli


For similar, but really difficult cases, see expect






share|improve this answer






















  • Expect did the trick. Thanks!
    – K Enz
    Feb 1 at 6:06

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













After exec cli, your shell script does not return to run the next line, sleep 2
To be exact, it no longer exists, because exec replaces the shell process by the new cli process.



I suspect you do not really want the effect of exec, and should remove it.



I am not really sure what you want to do, but assuming you want to run the command show config in cli, try just writing the command to it's input:



printf "show config" | cli


For similar, but really difficult cases, see expect






share|improve this answer






















  • Expect did the trick. Thanks!
    – K Enz
    Feb 1 at 6:06














up vote
1
down vote













After exec cli, your shell script does not return to run the next line, sleep 2
To be exact, it no longer exists, because exec replaces the shell process by the new cli process.



I suspect you do not really want the effect of exec, and should remove it.



I am not really sure what you want to do, but assuming you want to run the command show config in cli, try just writing the command to it's input:



printf "show config" | cli


For similar, but really difficult cases, see expect






share|improve this answer






















  • Expect did the trick. Thanks!
    – K Enz
    Feb 1 at 6:06












up vote
1
down vote










up vote
1
down vote









After exec cli, your shell script does not return to run the next line, sleep 2
To be exact, it no longer exists, because exec replaces the shell process by the new cli process.



I suspect you do not really want the effect of exec, and should remove it.



I am not really sure what you want to do, but assuming you want to run the command show config in cli, try just writing the command to it's input:



printf "show config" | cli


For similar, but really difficult cases, see expect






share|improve this answer














After exec cli, your shell script does not return to run the next line, sleep 2
To be exact, it no longer exists, because exec replaces the shell process by the new cli process.



I suspect you do not really want the effect of exec, and should remove it.



I am not really sure what you want to do, but assuming you want to run the command show config in cli, try just writing the command to it's input:



printf "show config" | cli


For similar, but really difficult cases, see expect







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 1 at 5:05

























answered Feb 1 at 4:59









Volker Siegel

10.2k33058




10.2k33058











  • Expect did the trick. Thanks!
    – K Enz
    Feb 1 at 6:06
















  • Expect did the trick. Thanks!
    – K Enz
    Feb 1 at 6:06















Expect did the trick. Thanks!
– K Enz
Feb 1 at 6:06




Expect did the trick. Thanks!
– K Enz
Feb 1 at 6:06


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay