为什么我的Linux服务器中的bash脚本不';是否无法将星号识别为具有相同前缀的所有文件?

为什么我的Linux服务器中的bash脚本不';是否无法将星号识别为具有相同前缀的所有文件?,linux,Linux,我有一个Linux实例,其中有一个cron作业,运行一个脚本,该脚本将我的ssl日志发送到aws帐户中的s3存储桶。 失败的脚本如下所示: /var/log/httpd/*log { compress compresscmd /bin/gzip compressoptions -9 compressext .gz dateext dateformat _%Y-%m-%d.log.%s

我有一个Linux实例,其中有一个cron作业,运行一个脚本,该脚本将我的ssl日志发送到aws帐户中的s3存储桶。 失败的脚本如下所示:

/var/log/httpd/*log {
    
      compress
      compresscmd /bin/gzip
      compressoptions -9
      compressext .gz
    
      dateext
      dateformat _%Y-%m-%d.log.%s
    
      rotate 14
      nomail
      missingok
      #size 5k
      create 640 root root
    
      sharedscripts
      postrotate
      sudo /sbin/service httpd reload > /dev/null 2>/dev/null || true
    
      BUCKET=*********
    
      SITE=*******
    
      sudo /usr/bin/s3cmd sync /var/log/httpd/access_log_*.gz s3://${BUCKET}/${SITE}/access_logs/access_logs/
      sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_access_log_*.gz s3://${BUCKET}/${SITE}/access_logs/ssl_access_logs/
      sudo /usr/bin/s3cmd sync /var/log/httpd/error_log_*.gz s3://${BUCKET}/${SITE}/error_logs/error_logs/
      sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_error_log_*.gz s3://${BUCKET}/${SITE}/error_logs/ssl_error_logs/
      sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_request_log_*.gz s3://${BUCKET}/${SITE}/request_logs/ssl_request_logs/
    
      endscript
    
    }
输出为:

ERROR: Parameter problem: Invalid source: '/var/log/httpd/access_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_access_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/error_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_error_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_request_log_*.gz' is not an existing file or directory
error: error running shared postrotate script for '/var/log/httpd/*log '
由于某种原因,我的bash脚本似乎无法识别如何使用星号,我也不知道为什么

非常感谢

编辑:
我确信文件夹中存在这些文件前缀,并且我正在以root用户身份运行脚本。

在脚本或终端上,路径全局扩展由shell(bash、zsh等)处理,而不是程序/或命令本身(*尽管它取决于程序/cmd实现)

对于
logrotate
config,postrotate命令由logrotate执行,而不是shell。要进行shell调用以便扩展'*',请尝试使用
/bin/bash-c

例如:


您能否验证目录
/var/log/httpd
中是否存在具有给定模式的文件。并且目录可以搜索执行命令的shell。如果您以root用户身份运行脚本,那么为什么要使用
sudo
?这不是bash脚本。请正确地重新标记问题。
sudo bash -c "/usr/bin/s3cmd sync /var/log/httpd/access_log_*.gz s3://${BUCKET}/${SITE}/access_logs/access_logs/"