A detailed description of the arithmetic operators for Bash programming under Linux (iii)
The shell arithmetic operation is represented as follows:
1. Let arithmetic operation expression
Let c= $A + $B
2. $[arithmetic operation expression]
c=$[$A + $B]
3, $ (arithmetic operation expression)
c=$ (($A + $B))
4. Expr must have a space between each operand and operator, and you want to use a command reference
c= ' expr $A + $B '
To illustrate:
1. Specify a user to determine whether the remaining lifetime of the user's password is less than the warning period;
Show "Password will expire-Warning" if it is less than the warning period; otherwise, "OK" is displayed
Tip: The maximum usage period minus the number of days that have been used is the remaining period of use;
Vim shadowdate.sh Create a script file and add the following:
#!/bin/bash
Username=willow Specify a user and set the variable
Rece= ' grep ' \< $USERNAME \> "/etc/shadow | cut-d:-f3 ' recent password change time
long= ' grep ' \< $USERNAME \> "/etc/shadow | cut-d:-f5 ' Maximum password usage period
Expi= ' grep ' \< $USERNAME \> "/etc/shadow | cut-d:-f6 ' warning period
Curr= ' Date +%s ' from 1970/01/01 to today, total number of seconds
Let today= $CURR/86400 from 1970/01/01 to today, how many days
#let userdays= $TODAY-$RECE notes: How many days a password has been used one of the table method methods
#USERDAYS =$[$TODAY-$RECE] Notes: How many days the password has been used one of the two table method
userdays=$ (($TODAY-$RECE)) password has been used for how many days one of the three table method
left= ' expr $LONG-$USERDAYS ' remaining period of use
If [$LEFT-lt $EXPI]; Then
echo "Password'll expire-Warning"
Else
echo "Password is OK"
Fi
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/FD/wKiom1cPA2uDae_9AAJfGcvYkYg712.jpg "title=" Shadowdate.jpg "alt=" Wkiom1cpa2udae_9aajfgcvykyg712.jpg "/>
chmod a+x shadowdate.sh granted execution rights
./shadowdate.sh Execute Script
This article is from the "Xavier Willow" blog, please be sure to keep this source http://willow.blog.51cto.com/6574604/1763691
A detailed description of the arithmetic operators for Bash programming under Linux (iii)