Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:linux_scripting [2016/12/01 15:33] alfred |
wiki2:linux_scripting [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 31: | Línea 31: | ||
| exit 1 | exit 1 | ||
| fi | fi | ||
| + | </code> | ||
| + | Si quieres que el script pare cuando haya un error interno añade la siguiente línea al inicio de este: | ||
| + | <code> | ||
| + | set -e | ||
| + | </code> | ||
| + | ===== Fast notes ===== | ||
| + | === Check if a directory or file exists === | ||
| + | Looking the status code of: | ||
| + | <code> | ||
| + | test -d /path | ||
| + | </code> | ||
| + | |||
| + | === Wait to press a key === | ||
| + | |||
| + | <code> | ||
| + | read -n1 -r -p "Press any key to continue..." key; | ||
| + | </code> | ||
| + | |||
| + | === Override a line in a config file === | ||
| + | <code> | ||
| + | sed -i 's/# auth-access = write/auth-access = write/' src/conf/svnserve.conf | ||
| + | sed -i 's/# password-db = passwd/password-db = passwd/' doc/conf/svnserve.conf | ||
| + | </code> | ||
| + | |||
| + | === Get formatted data === | ||
| + | get year-month-day from date | ||
| + | <code> | ||
| + | DATE=`date +%Y-%m-%d` | ||
| + | </code> | ||
| + | get year-month-day hour:minute:second from date | ||
| + | <code> | ||
| + | DATE=`date '+%Y-%m-%d %H:%M:%S'` | ||
| + | </code> | ||
| + | <code> | ||
| + | $ DATE=$(date +%y%m%d) | ||
| + | $ echo $DATE | ||
| + | 190523 | ||
| + | </code> | ||
| + | ===== Examples ===== | ||
| + | Some Django shortcuts: | ||
| + | <code> | ||
| + | resetmigrations() { | ||
| + | if [ -z "$1" ] | ||
| + | then | ||
| + | echo "No database supplied" | ||
| + | return | ||
| + | fi | ||
| + | echo "The $1 database is going to be reseted"; | ||
| + | read -n1 -r -p "Press any key to continue..." key; | ||
| + | find . -path "*/migrations/*.py" -not -name "__init__.py" -delete | ||
| + | find . -path "*/migrations/*.pyc" -delete | ||
| + | export PGPASSWORD=mysecretpassword; | ||
| + | dropdb -h 127.0.0.1 -U postgres $1 | ||
| + | createdb -T template0 -h 127.0.0.1 -U postgres $1 | ||
| + | python manage.py makemigrations | ||
| + | python manage.py migrate | ||
| + | } | ||
| </code> | </code> | ||