Hi i received an error
chage: user 'user' does not exist in /etc/passwd ")syntax error: invalid arithmetic operator (error token is "
Could anyone pls help me to identify my mistake. tq
#!/bin/bash
recipient="[email protected]" # Set the email address of the recipient
subject="Alibaba Cloud Pasword Change Reminder"
# Check the password expiration date
expiration_date=$(chage -l user | grep "Password expires" | awk -F ":" '{print $2}')
expiration_timestamp=$(date -d "$expiration_date" +%s)
current_timestamp=$(date +%s)
difference_in_seconds=$((expiration_timestamp-current_timestamp))
difference_in_days=$((difference_in_seconds/60/60/24))
if [ "$difference_in_days" -le 60 ]; then #Send an email if the password will expire within 60 days message="Hello,
This is a reminder to change your Alibaba Cloud account password. It is important to regularly update your password to ensure the security of your account.
Your password will expire in $difference_in_days days. Please be sure to change it before it expires.
Thank you,
Product Team"
echo "$message" | mail -s "$subject" "$recipient" #Send the email using the mail command
fi
chage -l user
is looking up information on the useruser
. I was expecting a variable for the user name. Also, you should check if the command is successful: