Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Linux Bash Scripting

Empfohlene Antworten

Hallo schreibe hier zum ersten mal, und hoffe das das Thema im richtigen Forum ist.

Also (ja man fängt so nicht an ;-) ) ich bin gerade an meinen ersten bash script dran momentan sieht es so aus:


#!/bin/bash


SEL=$1


## path to binaries

BIN_GPG='/usr/bin/gpg'


## path to password file

PWFILE="pw.txt"


## extension for crypted files

ENC_EXT=".gpg"


## gpg to encrypt

EXEC_ENC="gpg --force-mdc  --passphrase-file $PWFILE -c "


## Decrypt with Password

EXEC_DECP="gpg --decrypt --output"


## Decrypt with Password file


EXEC_DECPF="gpg --decrypt  --passphrase-file $PWFILE --output"


## shred

EXEC_SHR="shred -un 2"


## min/max password length

LEN_MAX="80"

LEN_MIN="6"


## root check

if [ "$(id -u)" != "0" ]; then

   echo "This script must be run as root"

   exit;

fi



case $SEL in

    --encrypt)

    ENC_FILE=$3

    METH=$2


        ##Password check and creat password

        if [ -f "$PWFILE" ]; then

            PW=`cat $PWFILE`

            PW_LEN=${#PW}


        else

            echo "Keine Password Datei vorhanden -> Password wird generiert und in der pw.txt abgelegt"

            MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

            LENGTH="70"



        while [ "${n:=1}" -le "$LENGTH" ]

        do

            PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"

            let n+=1

        done

            touch pw.txt

            echo "$PASS" >> pw.txt

        PW=`cat $PWFILE`

        PW_LEN=${#PW}

        fi


        ## check password length

        if [ "$PW_LEN" -gt "$LEN_MAX" ]; then

            echo "Password too long"

            exit

        elif [ "$PW_LEN" -lt "$LEN_MIN" ]; then

            echo "Password too short"

            exit

        fi


        ## With shred

        if [ "$METH" == "--shred" ]; then

            METH=$2

        else

            ENC_FILE=$2

        fi



        ## check file to encrypt and crypt


        if [ -f "$ENC_FILE" ]; then

            echo "Encrypting File: $ENC_FILE -> $ENC_FILE$ENC_EXT"

            $EXEC_ENC $ENC_FILE

        elif [ ! $ENC_FILE ]; then

            echo "File non existant or parameter empty"

            exit

        fi


        if [ -f "$ENC_FILE" ]; then

            echo "$ENC_FILE exist"

        else

            echo "$ENC_FILE not found -> exit"

            exit

        fi


        #if

        #    ["$METH" == "--shred"; then

        #    exec_SHRN=2

        #fi

        #if [ "METH" == "--shred EXEC_SHRN"; then

        #    read EXEC_SHRN

        #fi


        if [ "$METH" == "--shred" ]; then

            $EXEC_SHR $ENC_FILE $ENC_FILE

            echo "File was Delet"

            exit

        elif

            [ "$METH" == "" ]; then

            echo "Datei bleibt erhalten"

            exit

        fi


        ## check original file and delet with shred

        #if [ -f "$ENC_FILE" ]; then

        #    echo "$ENC_FILE exist and delet with shred"

        #    $EXEC_SHR $ENC_FILE $ENC_FILE

        #    echo "$ENC_FILE was delet"

        #elif [ ! "$ENC_FILE" ]; then

        #    echo "File wasn't deleted"

        #    exit

        #fi



        exit

        ;;


    --decrypt)

    ENC_FILE=$3

    DEC_FILE=$4

    METH=$2




        echo "Bitte Neuen Dateinamen fue die entschluesselte Datei angeben und den Pfad"

        read DEC_FILE

        if [ "$METH" == "--password" ]; then

            echo "Now decrypt $ENC_FILE with Password -> $DEC_FILE"

                    $EXEC_DECP $DEC_FILE $ENC_FILE

                    exit

        elif [ ! "$DEC_FILE" ]; then

            echo "File non existant or parameter empty, bitte --file oder --password fuer die password eingabe angeben"

            exit

        elif [ "$METH" == "" ]; then

            echo "Bitte --file oder --password fuer die password eingabe angeben"

            exit



        ## Decrypt with password file

        elif [ "$METH" == "--file" ]; then

            echo "Now decrypt $ENC_FILE  with Password File -> $DEC_FILE"

                $EXEC_DECPF $DEC_FILE $ENC_FILE

                exit

        elif [ ! "$DEC_FILE" ]; then

            echo "File non existant or parameter empty, bitte --file oder --password fuer die password eingabe angeben"


        elif [ "$METH" == "" ]; then

            echo "Bitte --file oder --password fuer die password eingabe angeben"

        exit

        fi


    exit

    ;;

    *)

            echo "Please write --decrypt or --encrypt, "

    exit

    ;;

So nun soll es so weitergehen dass das Script seine Einstellungen aus einer Config Datei ziehen soll. Ich denke ich weiß wie ich eine config Datei einbinde "source <pfad>", aber nun kommt das woran ich etwas hänge. Und zwar soll das Script wie gesagt die Daten aus einer config auslesen aber die Kommandozeile (sprich die daten so eingeben wie z.b ./test --encrypt --shred) soll trotzdem noch funktionieren. Könntet ihr mir da einen kleinen Tipp geben, oder erklären wie ich das umsetzten könnte. Danke im vor raus :-) .

Grüße Cas

So habe das "Problem nun gelöst *freu* hat zwar etwas gedauert aber ok.

Vor dem root check habe ich folgendes eingefügt

##config file

cnf="/root/tmp/test.cnf"


if [ "$METH" != "" ]; then

    echo "Alles gut"

else

 BIN_GPG=

 PWFILE=

 ENC_EXT=

 EXEC_ENC=

 EXEC_DECP=

 EXEC_DECPF=

 EXEC_SHR=

 LEN_MAX=

 LEN_MIN=


    source /root/tmp/test.cnf

fi

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.