簡體   English   中英

如何使用 sed 替換 shell 腳本中的 cron?

[英]How to replace a cron in a shell script using sed?

我需要使用 sed 或 awk 替換文件中的 cron 條目。

試過這個:沒用

sed -i 's/0 0 * * 0/0 1 * * 1/g' script.sh

腳本.sh

#!/bin/bash

mkdir -p .github/workflows

cd .github/workflows
touch semgrep.yml

cat << EOF > semgrep.yml
name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 0 * * 0'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04

請幫助我。

使用mikefarah/yq就地編輯文件 ( -i ):

yq -i '.on.schedule[].cron = "0 1 * * 1"' semgrep.yml

會變成一個semgrep.yml包含

name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 0 * * 0'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04

成一個包含

name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 1 * * 1'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM