
Ich habe diesen Teil des Shell-Skripts:
#!/bin/bash
shopt -s extglob
currentDate=$(date +%F)
echo $currentDate
command="grep $currentDate"
gcs3='s3://gc-reporting-pud-production/splunk_printer_log_files'
gcs3ls='aws s3 ls 's3://gc-reporting-pud-production/splunk_printer_log_files/SOUTH_ASIA/' --recursive '
ssyss3=s3://ssyssplunk
gcs3Current=$($gcs3ls|$command|sed 's/^.*\(splunk_printer.*\)/\1/g')
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
s3ls='aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive'
echo "ls: " $s3ls
egrepCommand="'$currentDate|Total'"
echo "grep: " $egrepCommand
totalSize=$($s3ls|egrep $currentDate\|Total|awk -F 'Total Size:' '{print $2}'|sed '/^$/d')
echo "total size: " $totalSize
IFS=$SAVEIFS
und ich bekomme diesen Fehler:
27.05.2019 ls: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive grep: '27.05.2019|Total' ./copyFilesFromS13.sh: Zeile 54: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive: Keine solche Datei oder kein solches Verzeichnis vorhanden. Gesamtgröße:
Was mache ich falsch ?
Antwort1
Sie haben IFS nur auf Zeilenumbruch und Rücktaste eingestellt. Daher $s3ls
wird nach der Erweiterung und Worttrennung aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive
als einzelnes Wort betrachtet. Bash versucht, dieses einzelne Wort als Befehl auszuführen, anstatt es aws
mit einer Reihe von Argumenten auszuführen.
Sie sollten Befehle wirklich nicht in Variablen speichern.Verwenden Sie stattdessen Arrays:
s3ls=(aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive)
#...
totalSize=$("${s3ls[@]}" | ...)