Skip to content

Instantly share code, notes, and snippets.

@upsilon
Created June 6, 2012 03:25
Show Gist options
  • Select an option

  • Save upsilon/2879694 to your computer and use it in GitHub Desktop.

Select an option

Save upsilon/2879694 to your computer and use it in GitHub Desktop.
演習課題をシェルから放り込みたくなったやっつけスクリプト
#!/bin/sh
# ./sfprog.sh 07
# ./sfprog.sh 07 problem-2012-mid-10-c q10.c
url_base="http://gamma.sf.cs.it-chiba.ac.jp/Class"
class_path="/2012/C-Programming"
#察しろ
user_id=""
session=""
if [ "$#" -eq 0 -o "$#" -eq 2 ]; then
echo "usage: $0 num title [infile]"
exit
fi
class_url="${url_base}${class_path}/${1}_program.jsp"
if [ "$#" -eq 1 ]; then
echo "課題一覧:"
curl --silent -b "JSESSIONID=${session}" $class_url | sed -e '/<option/! D' -e 's/^.*value="\(.*\)">\(.*\)$/ \1 \/ \2/g'
exit
fi
curl --silent -b "JSESSIONID=${session}" $class_url | sed -e '/<option/! D' -e 's/^.*value="\(.*\)">.*$/\1/g' | grep "^${2}$" > /dev/null
if [ "$?" -ne 0 ]; then
echo "invalid title"
echo
$0 $1
exit 1
fi
curl -b "JSESSIONID=${session}" -F "userid=${user_id}" -F "reporttitle=${2}" -F "uploaded=@${3};filename=`basename ${3}`" "${url_base}/SimpleFileUpload" && echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment