Created
October 25, 2020 15:44
-
-
Save badmonkey7/0187824237423c4528b2910647411db4 to your computer and use it in GitHub Desktop.
根据task.py文件,动态生成flag及其需要的数据,并打包成附件到指定文件夹中
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
| #! /usr/bin/bash | |
| # 动态附件的数量 | |
| if [ $# -lt 2 ]; then | |
| echo "请指定动态附件的数量,及题目名称!如:dynamic_task.sh 10 simple_math"; | |
| exit 0; | |
| else | |
| number=$1 | |
| save_path=$2 | |
| fi | |
| # 合法性检查 | |
| if [ $number -lt 0 ]; then | |
| echo "请输入大于0的整数"; | |
| exit 0; | |
| fi | |
| # 检查文件是否存在 | |
| filename="task.py"; | |
| if [ ! -x $filename ]; then | |
| echo "task.py文件不存在,或者没有执行权限"; | |
| exit 0; | |
| fi | |
| # 检查flag文件是否存在 | |
| flag="flag.py" | |
| if [ ! -x $flag ]; then | |
| echo "flag.py文件不存在,或者没有执行权限"; | |
| exit 0; | |
| fi | |
| # 创建保存文件夹 | |
| mkdir -p "$save_path/source"; | |
| mkdir -p "$save_path/attachment"; | |
| for (( i = 0; i < $number; i++ )); do | |
| source_dir="source_code_$i"; | |
| attachment_dir="attachment_$i"; | |
| mkdir "$source_dir" | |
| mkdir "$attachment_dir"; | |
| # 动态生成flag及其附件 | |
| python $filename | cat >> "$attachment_dir/output"; | |
| cp $filename "$attachment_dir/$filename"; | |
| # 打包附件,然后移动附件到对应的源码文件中 | |
| tar -cvzf "$attachment_dir.tar.gz" "$attachment_dir"; | |
| mv "$attachment_dir.tar.gz" "$save_path/attachment/"; | |
| # 将源码移动到当前源码文件夹下 | |
| flag_txt="flag.txt" | |
| cp $flag_txt "$source_dir/$flag_txt"; | |
| mv "$attachment_dir/"* "$source_dir" | |
| # 将当前的源码文件夹,移动到主源码文件夹下 | |
| mv "$source_dir" "$save_path/source/"; | |
| # 删除当前源码文件夹及当前附件文件夹 | |
| rm -rf "$source_dir"; | |
| rm -rf "$attachment_dir"; | |
| # echo "$attachment_dir"; | |
| done | |
| echo "all done"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment