{"id":171,"date":"2012-01-23T12:33:13","date_gmt":"2012-01-23T17:33:13","guid":{"rendered":"https:\/\/www.vhdesigns.com\/?p=171"},"modified":"2012-01-23T12:33:13","modified_gmt":"2012-01-23T17:33:13","slug":"simple-telnet-automation-using-expect-this-is-a-nice-simple-bash-shell-script-to-automate-and-test-telnet-servers-its-a-nice-script-and-well-commented-hope-you-enjoy-all-comments-welcome","status":"publish","type":"post","link":"https:\/\/vhdesigns.com\/index.php\/2012\/01\/23\/simple-telnet-automation-using-expect-this-is-a-nice-simple-bash-shell-script-to-automate-and-test-telnet-servers-its-a-nice-script-and-well-commented-hope-you-enjoy-all-comments-welcome\/","title":{"rendered":"Simple Telnet Automation Using Expect &#8211; This is a nice simple bash shell script to automate and test telnet servers, it&#8217;s a nice script and well commented. Hope you enjoy, all comments welcome."},"content":{"rendered":"<p><a href=\"http:\/\/www.osix.net\/modules\/article\/?id=35\">Simple Telnet Automation Using Expect &#8211; This is a nice simple bash shell script to automate and test telnet servers, it&#8217;s a nice script and well commented. Hope you enjoy, all comments welcome.<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<form id=\"rateform\" action=\"https:\/\/www.osix.net\/modules\/article\/?id=35\" method=\"POST\" name=\"rateform\">\n<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<td style=\"font-size: 12px;\"><strong>Explanation of Code (Bash Shell)<\/strong><\/p>\n<p>The code works by the user entering an argument, this argument could be either<br \/>\n-a, -h, or a server nickname. The -a argument would cause the bash shell to<br \/>\nlog in and out of every server located in the autotelrc file, using the usernames<br \/>\nand passwords provided. The -h argument would bring up a small help message.<br \/>\nThe code written is heavily commented but some parts deserve some explanation<br \/>\nas to their rationale.<\/p>\n<div class=\"code\" style=\"font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600; background-color: #fafafa; border-width: 1px; border-style: solid; border-image: initial; border-color: #d1d7dc;\">\u00a0if [ &#8220;z$1&#8221; == &#8220;z&#8221; ]; then<br \/>\necho &#8220;You didn&#8217;t type a valid argument.&#8221;<\/div>\n<p>The z in front of the $1 argument is to tell if the user entered an argument<br \/>\nor not. If something isn&#8217;t entered it returns just the z by itself and the error<br \/>\necho occurs.<br \/>\nIf this condition is not true then the script then proceeds to the else statement.<br \/>\nUnder this statement is another if statement. This takes account for the -a,<br \/>\n-h and server nickname argument. The counter I has been initialised at 2, this<br \/>\nsaves us a line of code, if I = 2 then we would have to use another cut to trim<br \/>\noff the hashes in the rc file. So just incrementing the counter by 1 helps us<br \/>\nhere. If the -h argument is used then the if statement give echoes us the help<br \/>\nmessage, which explains the usage to the user. If the -a argument is used, then<br \/>\nthe statement then proceeds to work it&#8217;s way through the rc file and telnet<br \/>\ninto each using the expect script (explained later) and then log out, this is<br \/>\nuseful to a network administrator to test various telnet machines. If the user<br \/>\nspecifies an argument with a server nickname then the script searches through<br \/>\nthe rc file for the relevant line and telnets into it using the expect script.<br \/>\nThe code used here was as follows.<\/p>\n<div class=\"code\" style=\"font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600; background-color: #fafafa; border-width: 1px; border-style: solid; border-image: initial; border-color: #d1d7dc;\">\u00a0If [ $1 == $Nickname ]; then<br \/>\n.\/telExpect.exp $Machine $Username $Password<br \/>\nFi #finish if statement<\/div>\n<p>This was chosen instead of using the getops because it is much shorter code,<br \/>\nand in searching a small file there is not much performance difference.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/form>\n","protected":false},"excerpt":{"rendered":"<p>Simple Telnet Automation Using Expect &#8211; This is a nice simple bash shell script to automate and test telnet servers, it&#8217;s a nice script and<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-tips"],"_links":{"self":[{"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":0,"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vhdesigns.com\/index.php\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}