
Tengo esta parte del script de shell:
#!/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
y recibo este error:
2019-05-27 ls: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive grep: '2019-05-27|Total' ./copyFilesFromS13.sh: línea 54: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive: No existe tal tamaño total de archivo o directorio:
Qué estoy haciendo mal ?
Respuesta1
Ha configurado IFS solo para nueva línea y retroceso. Entonces, $s3ls
después de la expansión y división de palabras, se aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive
tomará como una sola palabra. Bash intenta ejecutar esta única palabra como un comando, en lugar de ejecutarla aws
con un montón de argumentos.
Realmente no deberías almacenar comandos en variables.Utilice matrices en su lugar:
s3ls=(aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive)
#...
totalSize=$("${s3ls[@]}" | ...)