BASH: calculate number of days to account expiration

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.
I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash
join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
where
$1 = username
$9 = number of days since last password change, calculated from 1/1_1970
$14 = number of days to password expiry date, calculated from 1/1_1970
I can get a similar number as $9 and $14 for the current date
expr $(date +%S) /86400
Question:
How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?
bash date accounts
add a comment |Â
up vote
2
down vote
favorite
Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.
I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash
join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
where
$1 = username
$9 = number of days since last password change, calculated from 1/1_1970
$14 = number of days to password expiry date, calculated from 1/1_1970
I can get a similar number as $9 and $14 for the current date
expr $(date +%S) /86400
Question:
How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?
bash date accounts
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.
I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash
join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
where
$1 = username
$9 = number of days since last password change, calculated from 1/1_1970
$14 = number of days to password expiry date, calculated from 1/1_1970
I can get a similar number as $9 and $14 for the current date
expr $(date +%S) /86400
Question:
How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?
bash date accounts
Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.
I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash
join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
where
$1 = username
$9 = number of days since last password change, calculated from 1/1_1970
$14 = number of days to password expiry date, calculated from 1/1_1970
I can get a similar number as $9 and $14 for the current date
expr $(date +%S) /86400
Question:
How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?
bash date accounts
bash date accounts
edited 42 mins ago
Rui F Ribeiro
37.1k1274118
37.1k1274118
asked 2 hours ago
DavDav
829
829
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Use echo as follows:
echo "$(($9-$(date +%s)/86400 ))"
$((...)) is an arithmetic expansion.
The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.
$((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.
or
echo "$9-$(date +%s)/86400" | bc
bc stands for basic calculator and it can handle mathematical operations.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Use echo as follows:
echo "$(($9-$(date +%s)/86400 ))"
$((...)) is an arithmetic expansion.
The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.
$((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.
or
echo "$9-$(date +%s)/86400" | bc
bc stands for basic calculator and it can handle mathematical operations.
add a comment |Â
up vote
3
down vote
accepted
Use echo as follows:
echo "$(($9-$(date +%s)/86400 ))"
$((...)) is an arithmetic expansion.
The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.
$((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.
or
echo "$9-$(date +%s)/86400" | bc
bc stands for basic calculator and it can handle mathematical operations.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Use echo as follows:
echo "$(($9-$(date +%s)/86400 ))"
$((...)) is an arithmetic expansion.
The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.
$((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.
or
echo "$9-$(date +%s)/86400" | bc
bc stands for basic calculator and it can handle mathematical operations.
Use echo as follows:
echo "$(($9-$(date +%s)/86400 ))"
$((...)) is an arithmetic expansion.
The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.
$((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.
or
echo "$9-$(date +%s)/86400" | bc
bc stands for basic calculator and it can handle mathematical operations.
edited 1 hour ago
answered 1 hour ago
Goro
9,63764689
9,63764689
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475777%2fbash-calculate-number-of-days-to-account-expiration%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
