# [Development] Make SecureCRT scripts simpler ###### tags: `development`, `python`, `SecureCRT`, `automated script execution` [toc] ## Motivation In a scenario, when developing new functions in a firmware or a binary, there are plenty of duplicated actions to do. For example, I often build a binary and scp it from a server to the other. And then, I download it through TFTP from DUT to my server. Finally, I can execute and debug. These actions are **oneshot** and are launched again and again. In the other scenario, we are going to do a burn-in test to check if a function works fine repeatedly like a rebooting test. This is a **periodic** task here. ## Idea These oneshot or periodic tasks can be done by different python scripts. And you can create plenty of buttons in the button bar to run those scripts. But, in my opinion, it is not only inconvenient but inefficient. Therefore, I start to think how to make it better? Could I just run a python script and load those oneshot and periodic tasks from the other config file? And could I just select a proper config to launch from that script? I decide to make it by myself. I learn SecureCRT python script in detail. I write the other [SecureCRT python script learning note](https://hackmd.io/@TomasZheng/HkPixB38L) to record API they provide. And I make rules for the config file according to SecureCRT screen object's API. ## Implementation ### Prerequisite - SecureCRT Version: 8.7.1 - Python Version: 2.7.17 ![](https://i.imgur.com/cJlpZip.png) ![](https://i.imgur.com/We4HIPP.png) My main python script is named launch_cfg.py. When running launch_cfg.py in SecureCRT, all .cfg file will be listed in a window and users can enter a number corresponding to a .cfg file. And then, it will load a that .cfg file and launch all commands in it in order. It is worthy noticing that oneshot and periodic task cannot be arranged in the same .cfg. They are exclusive. ### Make a cfg file Here, I am going to explain how to make a cfg file. - Comment A line starting with symbol # will be ignored. And a pair of symbol ''' are a block comment. - Command entry Except for the action "wait_period", each line is a command entry which consist of "Tabname", "Command" and "Action". - **Tabname** Like "serial-com4", it is a tab to launch a command with an action. - **Command** Like "ls -al", it is a command to launch. - **Action** To wait or not to wait for something like a time period or a specific string and so on. Include these keywords, ***no_wait***, ***wait_time***, ***wait_string***, ***wait_both*** and ***wait_period***. Below table shows the usage of them. | Action | Description | | ----------- | -------------------------------------------------------------------- | | no_wait | No any delay after a command launched. | | wait_time *t* | Set a time delay *t* after a command launched. | | wait_string *pattern* | Block the script until a matched string *pattern* occured </br>on the screen. | | wait_both *t pattern* | A combination of wait_time and wait_string. | | wait_period *t* | Regard this .cfg as a periodic task with period *t* seconds;</br> default is an oneshot task. | ### ScreenShot ![](https://i.imgur.com/3Vgq8PF.png) To make it more efficient, we can set a hotkey to run my script launch_cfg.py by **OPTIONS -> Session Options -> Terminal -> Mapped Keys** As show below. ![](https://i.imgur.com/tVG2RzE.png) ### Source code {%gist 05b25ee8a0eacf7b3bc763d1c9969e71%} ## Summary This implementation makes it easy and simple for users who are not familar with Python. But, it is not good enough for advanced application. If you need advanced application, you can refer to https://github.com/jamiecaesar/securecrt-tools.