-
Notifications
You must be signed in to change notification settings - Fork 8
Shell Script
Berikut ini kita akan ulas tentang otomatisasi dalam Shell Script dengan Regular expression
sed 's/ [ ]* / /g'
\_/ | \____/ | |
| | | | \- g=globally (not just one occurence)
| | | |
| | | \- to
| | |
| | \- from
| |
| \- s=substitute
|
\- program sed
The from part:
/ [ ]* /
| \_/|
| | \- repeated 0-infinite times
| |
| \- group of characters
|
\- boundary
$ echo 'href="{{ grandchild.url }}"' | \
sed 's|href="{{ grandchild.url }}"|href="/market{{ grandchild.url }}"|g'
href="/market{{ grandchild.url }}"
$ echo 'href="{{ grandchild.url }}"' | \
sed 's|href="{{ \([a-zA-Z0-9_]*\).url|href="/market{{ \1.url|g'
href="/market{{ grandchild.url }}"
some text here
blah blah 123
another new line
some other text as well
another line
$ sed '/text\|blah/!d' file
some text here
blah blah 123
some other text as well
$ sed '/X/ {/Y/! s/replace/with/}' << EOF
X replace X
X replace Y
Y replace X
Y replace Y
EOF
X with X
X replace Y
Y replace X
Y replace Y
$ export DIR=/path/dir && cd $DIR && chmod -R +x *
$ find . -maxdepth 1 -type f -name '*.sh' -exec {} \; > results.out
$ export DIR=/path/dir && cd $DIR && chmod -R +x *
find . -maxdepth 2 -type f -name '*.sh' | sort | bash > results.out
bash: 1: ./assets/main.sh
bash: 2: ./builder/clean.sh
bash: 3: ./builder/concept/compose.sh
bash: 4: ./builder/concept/market.sh
bash: 5: ./builder/concept/services.sh
bash: 6: ./builder/curl.sh
bash: 7: ./builder/identity.sh
bash: 8: ./concept/compose.sh
bash: 9: ./concept/market.sh
bash: 10: ./concept/services.sh
bash: 11: ./product/compose.sh
bash: 12: ./product/market.sh
bash: 13: ./product/services.sh
bash: 14: ./xferlog.sh
export DIR=/path/dir && cd $DIR && chmod -R +x *
find . -type f -name '*.sh' | sort | bash > results.out
$ echo `
#!/bin/sh
if [ -d /home/chetabahana/.docker/backend ]; then
cd /home/chetabahana/.docker/backend && docker-compose down --volumes
cd .. && sudo rm -rf /home/chetabahana/.docker/backend
fi
gcloud source repos clone github_chetabahana_backend backend
cd /home/chetabahana/.docker/backend/scripts && chmod +x main.sh && ./main.sh
' > init.sh
$ chmod +x init.sh
$ echo `
FROM alpine
COPY init.sh /
CMD ["/init.sh"]
' > Dockerfile
$ gcloud builds submit --tag gcr.io/[PROJECT_ID]/init .
$ gcloud compute --project "chetabahana" ssh --zone "us-central1-c" "backend"
chetabahana@backend:~$ /home/chetabahana/.docker && docker run gcr.io/[PROJECT_ID]/init
$ echo '
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/init', '.' ]
images:
- 'gcr.io/$PROJECT_ID/init'
' > cloudbuild.yaml
$ gcloud builds submit --config cloudbuild.yaml .
$ gcloud compute --project "chetabahana" ssh --zone "us-central1-c" "backend"
chetabahana@backend:~$ /home/chetabahana/.docker && docker run gcr.io/[PROJECT_ID]/init
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["compute", "ssh", "${_USER_NAME}@${_INSTANCE_NAME}", "--zone", "${_ZONE}",
"--command", "cd ${_DOCKER_DIRECTORY} && docker run gcr.io/[PROJECT_ID]/init"]
substitutions:
_ZONE: us-central1-c
_USER_NAME: chetabahana # default value
_INSTANCE_NAME: backend # default value
_DOCKER_DIRECTORY: /home/chetabahana/.docker # default value
timeout: "1600s"
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["compute", "ssh", "${_USER_NAME}@${_INSTANCE_NAME}", "--zone", "${_ZONE}",
"--command", "cd ${_DOCKER_DIRECTORY} && echo '
#!/bin/sh\n
if [ -d /home/chetabahana/.docker/backend ]; then\n
\tcd /home/chetabahana/.docker/backend && docker-compose down --volumes\n
\tcd .. && sudo rm -rf /home/chetabahana/.docker/backend\n
fi\n
gcloud source repos clone github_chetabahana_backend backend\n
cd /home/chetabahana/.docker/backend/scripts && chmod +x main.sh && ./main.sh\n
#EOF\n
' > init.txt && rm -rf init.sh && mv init.txt init.sh && chmod +x init.sh && ./init.sh"]
substitutions:
_ZONE: us-central1-c
_USER_NAME: chetabahana # default value
_INSTANCE_NAME: backend # default value
_DOCKER_DIRECTORY: /home/chetabahana/.docker # default value
timeout: "1600s"
This documentation is mapped under Mapping and licensed under Apache License, Version 2.0.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2018-2020 Chetabahana Project
You are on the wiki of our repo
- Site
- Main
- Project
- Pratinjau
- Pola Dasar
- Bagan Kerja
- Field Tutorial
- Cloud Site API
- Google Ads API
- Cloud Tasks API
- Google Trends API
- Basis Implementasi
- Beranda
- Perangkat
- Pasang Aplikasi
- Penyetelan Aplikasi
- Menyiapkan Frontend
- Menjalankan Backend API
- Menjalankan Toko