Last active
November 26, 2019 09:39
-
-
Save johnhaldeman/9671563 to your computer and use it in GitHub Desktop.
Guardium Simple Expect Script for Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # \ | |
| exec tclsh "$0" ${1+"$@"} | |
| package require Expect | |
| # This is a simplified version of the Guardium expect script found here: | |
| # http://www-01.ibm.com/support/knowledgecenter/SSMPHH_9.1.0/com.ibm.guardium91.doc/how_to/topics/how_to_automate_execution_of_guardapi_commands.html?lang=en | |
| # The script runs some guardAPI calls located in a provided file. | |
| # The script is simpler in that it does not invoke set guiuser from a guardcli account | |
| # The script has also been adapted to take care of some of the esoterics involved with running TCL under the Windows | |
| # platform. It was built for ActiveState TCL spawning an OpenSSH session. This allows execution | |
| # in Windows for those those who don't have a Linux environment where they can install expect | |
| # USAGE: ./guardcli.tcl <g-machine> <cli-usr> <cli-pwd> <grdAPI-call-file> | |
| # Activstate TCL Instructions: | |
| # 1) Download and install the 32-bit version of ActiveState TCL: http://www.activestate.com/activetcl | |
| # 2) Once Installed, add the Expect package using their teacup utility: | |
| # From the command line: teacup install Expect | |
| # OpenSSH (the other pre-requisite) can be downloaded from here: http://sourceforge.net/projects/sshwindows/ | |
| # -------------------------------------------------------------------------------- | |
| # Copyright (c) 2014 by John Haldeman at Information Insights (john.haldeman@infoinsightsllc.com) | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy of | |
| # this software and associated documentation files (the "Software"), to deal in | |
| # the Software without restriction, including without limitation the rights to | |
| # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
| # of the Software, and to permit persons to whom the Software is furnished to do | |
| # so, subject to the following conditions: | |
| # The above copyright notice and this permission notice shall be included in all | |
| # copies or substantial portions of the Software. | |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| # SOFTWARE. | |
| # -------------------------------------------------------------------------------- | |
| set timeout 60 | |
| set gMachine [lindex ${argv} 0] | |
| set cli_user [lindex ${argv} 1] | |
| set cli_password [lindex ${argv} 2] | |
| set commands_file [lindex ${argv} 3] | |
| if { $gMachine == "" || $cli_user == "" || $cli_password == "" || $commands_file == "" } { | |
| send_user "USAGE: ./guardcli.tcl <g-machine> <cli-usr> <cli-pwd> <file> \n" | |
| exit | |
| } | |
| set file [open $commands_file r] | |
| spawn ssh $cli_user@$gMachine | |
| expect "Are you sure you want to continue connecting (yes/no)?" | |
| exp_send "yes\r" | |
| expect "password:" | |
| exp_send "$cli_password\r" | |
| expect ">" | |
| exp_send "\r" | |
| expect ">" | |
| while {[gets $file inline] != -1} { | |
| exp_send "$inline\r\r" | |
| expect "ok" | |
| } | |
| exp_send -- "quit\r" | |
| expect eof | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use Expect in windows , and ssh a server but when i use spawn, it respond me some unknown thing. Would you help me with this.
(System32) 70 % spawn ssh wuchengbo@192.168.1.50
ϵͳÕҲᄏᄉᄑָᄊᄄᄉÄÎļþᄀᆪ
when i use spawn ssh , all get this