tcl入门

使用了一段时间Expect自动化工具简介里面的expect脚本,发现少了一些功能: 怎么给expect脚本传参数呢? expect怎么调用 bash/sh外部命令呢? expect怎么操作字符串呢? tcl 前面的文章Expect命令里面提到过,expect 使用的是Tcl/tk的语法。 所以 大家Google 一下 tcl tutorial就可以解决上面三个问题了。 tcl argc argc Tcl tutorial Tcl regexp new expect script 结合上面的3篇教程我把上篇文章自动化ssh 登陆的脚本优化如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #!/usr/bin/expect -f # for anyone not familar with expect # should read this awesome article # https://www.pantz.org/software/expect/expect_examples_and_tips.html if { $argc != 1} { puts "must set one argument for server_A host ip" puts "./login.tcl 1.1.2.2" exit 1 } set timeout 15 #set info [gets stdin] set info [exec privateRESTfullAPI2GetPwd -host $argv] set result [regexp {\"([^\"]*)\"[^\"]*\"([^\"]*)\"[^\"]*\"([^\"]*)\"} $info match host pw1 pw2] send_user "going to connected to server_A\n" spawn ssh -q -o StrictHostKeyChecking=no nobody@host expect { timeout { send_user "\ntimeout Failed to get password prompt, is VPN on?\n"; exit 1 } eof { send_user "\nSSH failure for server_A\n"; exit 1 } "*assword:" } send "$pwd1\r" expect { timeout {send_user "\nSSH failure for server_B\n"; exit 1 } "Last login:*" } send "su -\r" expect { eof { send_user "\nSSH failure check your password \n"; exit 1 } "密码" } send "$pw2\r" interact 简单解释上面的脚本: ...

May 19, 2020 · datewu

TCP/IP教程

本文不定期更新 :) 上个礼拜逛Hacker News看到推荐了一份写于1991年介绍TCP/IP协议的文章A TCP/IP Tutorial。 初略的扫了几眼,发现不错,加入了收藏夹。 昨天晚上抽出时间来细读了一遍觉得很有翻译的价值,于是试着翻译一下: Introduction This tutorial contains only one view of the salient points of TCP/IP, and therefore it is the “bare bones” of TCP/IP technology. It omits the history of development and funding, the business case for its use, and its future as compared to ISO OSI. Indeed, a great deal of technical information is also omitted. What remains is a minimum of information that must be understood by the professional working in a TCP/IP environment. These professionals include the systems administrator, the systems programmer, and the network manager. ...

April 13, 2020 · datewu

Makefile简介

网络上关于 makefile的教程有很多,由于我日常不是写c/c++的, 不常使用makefile,需要用的时候总是要重新Google搜索makefile的语法。 索性整理出来这篇 makefile 教程,备忘。 教程 Makefile简易教程: 基本语法 1 2 3 4 target: dependency1 dependency2 ... [TAB] action1 [TAB] action2 ... 下面的makefile摘抄自GNU Make in Detail for Beginners,这篇入门文章把makefile的语法写的非常透彻。 推荐大家多读几遍 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 ##### makefile for compile C programs # Compiler to use CC = gcc # -g for debug, -O2 for optimise and -Wall additonal messages OPTIONS = -O2 -g -Wall # Directory for header file INCLUDES = -I . # List of objects to be build OBJS = main.o module.o .PHONY: all list clean all: ${OBJS} @echo "Building..." # print "Building..." message ${CC} ${OPTIONS} ${INCLUDES} ${OBJS} -o main_bin %.o: %.c # '%' pattern wildcard matching ${CC} ${OPTIONS} ${INCLUDES} -c %.c list: @echo $(shell ls) # print output of command `ls` clean: @echo Cleaning up... -rm -rf *.0 # '-' prefix for ignoring errors and continue execution -rm main_bin #### makefile for img manage FILES = $(shell find imgs -type f -iname "*.jpg" | sed 's/imgs/thumb/g') CONVERT_CMD = convert -resize "100x100" $< $@ MSG = "\nUpdating thumbnail" $@ all_thumb: ${FILES} thumb/%.jpg: imgs/%.jpg ${MSG} ${CONVERT_CMD} thumb/%.JPG: imgs/%.JPG ${MSG} ${CONVERT_CMD} clean_all: @echo Cleaning up files... -rm -rf thumb/*.{jpg,JPG} 变量 赋值 Simple assignment (:=) We can assign values (RHS) to variables (LHS) with this operator, for example: CC := gcc. With simple assignment (:=), the value is expanded and stored to all occurrences in the Makefile when its first definition is found. ...

July 27, 2018 · datewu