Recommended workflows in Alfred

Finally I purchase Alfred for workflows.

A Workflow is a combination of actions, and the killer feature in Alfred powerpack. In Alfred, we can import existing workflows or create our own workflows — to run a series of actions, which will dramatcially improve productivity.

My workflow lists

Before writing this post, I spent about half an hour on Alfred Workflows to go through all existing workflows based on the AlfredWorkflow repo by hzlzh and select following workflows as enhancement of Alfred.

There is another workflow repo by @zenorocha.

And here’s my lists.

Read More

expect 脚本编程

在多个机器上批量执行任务脚本的时候,经常需要输ssh密码,但是出于安全性(明文密码命令容易被history出来)和交互性命令(ssh等命令需要强制用户输入而不能通过参数输入)的限制,需要找一些新的办法。拍脑袋想到的有2个。

1、将自己的ssh 公钥上传到这些机器上(但第一次上传的时候,依然需要输密码,又绕回去了)

2、使用ssh -F configfile (看了下man ssh 和 man ssh_config,感觉太难配)

网上搜索了一阵,发现 expect 脚本编程。大概来说,基本上登录交互的东西都可以搞定。

expect - programmed dialogue with interactive programs, Version 5 (一个可以编程的交互对话程序)
下面上代码,完成登录,执行cmd command,返回结果,退出的功能。

1 #!/usr/bin/expect -f
2
3 # — set all file list —
4 #set db_box myssh-target
5 set db_box [lrange $argv 0 0]
6 set pw mypassword
7
8 spawn ssh $db_box
9 set timeout -1
10
11 expect {
12 “Are you sure you want to continue connecting (yes/no)? “ {
13 send “yes\r”;
14 exp_continue
15 }
16 “hector@$db_box’s password: “ {
17 send “$pw\r”
18 set timeout -1
19 expect “*bash-3.2$ “ {
20 send “grep topic= yinst set | grep coke_queue_daemon.daemon_dir | cut -f2 -d ':'/subscription/ -r | cut -f2 -d ‘:’ | cut -f2 -d ‘=’\r”
21 send “exit\r”
22 }
23 }
24 }
25 interact

expect的精髓就在于这个词本身,你expect什么输出,对应什么输入,都可以控制。具体情况man写得很详细,但一般工作照着上面这个改就可以了。

Read More