Search code examples
bashamazon-s3amazon-ec2redhat

Unable to execute bash script with cronjob rhel 9


I have created a user called abcservice with useradd abcservice --shell /usr/sbin/nologin and I have a bash script(auto.sh) with the contents:

#!/bin/bash

# Download Python script from S3 bucket
aws s3 cp s3://myscript/local_account.py /tmp/local_account.py

# Run the script
# The script will push the report to S3 bucket
sudo python3 /tmp/local_account.py

My cronjob settings are * * * * * /bin/bash /tmp/auto.sh (for testing)

For some reason, abcserviec is unable to execute the cronjob... The auto.sh has permission of 777

I've check the user, group, /var/log/messages, IAM roles and policies, SELinux, and crond. The auto.sh can be executed normally manually.


Solution

  • Try this with your cronjob: * * * * * /bin/bash /tmp/auto.sh >> output.log 2>&1

    I think the issue might be the AWS command in auto.sh is not set up correctly. You may need to use the full path for the AWS command in your auto.sh script. You can find the full path by running this command: which aws.

    /path/to/command/aws cp s3...