Last active
November 28, 2018 15:54
-
-
Save kujyp/2012803263c5f69cfb45f9cc858d490d to your computer and use it in GitHub Desktop.
Shell script Cheat Sheets
This file contains 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
#!/bin/bash | |
if [ -z "${LOCAL_USER_ID}" ]; then | |
echo LOCAL_USER_ID is empty | |
exit 1; | |
fi | |
if [ -z "${LOCAL_GROUP_ID}" ]; then | |
echo LOCAL_GROUP_ID is empty | |
exit 1; | |
fi | |
UID_DUPLICATED_USER=`awk -F: '{ if ($3 == LOCAL_USER_ID) print $1 }' LOCAL_USER_ID="${LOCAL_USER_ID}" /etc/passwd` | |
if [ -n "${UID_DUPLICATED_USER}" ]; then | |
echo Deleting uid duplicated user, ${UID_DUPLICATED_USER} | |
userdel ${UID_DUPLICATED_USER} | |
fi | |
echo Add ftp user, as ${LOCAL_USER_ID}:${LOCAL_GROUP_ID}\(uid:gid\) | |
groupadd -g ${LOCAL_GROUP_ID} -o ftp | |
useradd -o -u ${LOCAL_USER_ID} -g ${LOCAL_GROUP_ID} ftp | |
exec "$@" |
This file contains 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
#/bin/bash | |
FTP_USER=myuser | |
FTP_PASS=mypass | |
FTP_PORT=8021 | |
# Do not use Alphabetic domain name as FTP_ADDRESS. | |
# Use numeric ip address. | |
FTP_ADDRESS="FIXME" | |
if [ "${FTP_ADDRESS}" = "FIXME" ]; then | |
echo "Fix FTP_ADDRESS first." | |
exit 1; | |
fi | |
echo -e "Example usages\n\ | |
- ./start.sh /Users/jaeyoung/workspace/docker-vsftpd\n\ | |
" | |
if [ -z "${1}" ]; then | |
echo "PATH Variable is empty" | |
exit 1; | |
fi | |
FTP_PATH=$1 | |
docker run -d -v "${FTP_PATH}":/home/vsftpd/${FTP_USER} \ | |
-p 8020:20 -p ${FTP_PORT}:21 -p 21100-21110:21100-21110 \ | |
-e LOCAL_USER_ID=`id -u` -e LOCAL_GROUP_ID=`id -g` \ | |
-e FTP_USER=${FTP_USER} -e FTP_PASS=${FTP_PASS} \ | |
-e PASV_ADDRESS=${FTP_ADDRESS} -e PASV_MIN_PORT=21100 -e PASV_MAX_PORT=21110 \ | |
--name vsftpd --restart=always vsftpd |
This file contains 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
#!/bin/bash | |
# Tested Environments : Centos7 | |
get_script_path() { | |
SCRIPT=`readlink -e $0` | |
echo `dirname $SCRIPT` | |
} | |
cd_into_script_path() { | |
SCRIPT_PATH=`get_script_path` | |
cd ${SCRIPT_PATH} | |
} | |
cd_into_script_path | |
source ../configs/config.sh | |
rm -rf ${COPY_PATH} | |
cp -r ${PROJ_PATH} ${COPY_PATH} | |
This file contains 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
#!/bin/bash | |
# Tested Environments : Centos6 | |
start_script_on_background() { | |
echo "nohup ${1} > ${2} &" | |
nohup ${1} > ${2} & | |
} | |
get_script_path() { | |
SCRIPT=`readlink -e $0` | |
echo `dirname $SCRIPT` | |
} | |
SCRIPT_PATH=`get_script_path` | |
echo "SCRIPT_PATH: ${SCRIPT_PATH}" | |
LOGDIR="${SCRIPT_PATH}/../static" | |
PROCESS_NAME=express | |
CMD="yarn start" | |
echo "[DESC]: cd ${SCRIPT_PATH}/.." | |
cd "${SCRIPT_PATH}/.." | |
start_script_on_background "${CMD}" "${LOGDIR}/nohup_${PROCESS_NAME}.txt" |
- append file as root
searching query: sudo append
https://superuser.com/questions/136646/how-to-append-to-a-file-as-sudo
echo "output" | sudo tee -a file
or
sudo bash -c "somecommand >> somefile"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
searching query: shell color, echo color
https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux