LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Containers
User Name
Password
Linux - Containers This forum is for the discussion of all topics relating to Linux containers. Docker, LXC, LXD, runC, containerd, CoreOS, Kubernetes, Mesos, rkt, and all other Linux container platforms are welcome.

Notices


Closed Thread
  Search this Thread
Old 05-06-2022, 03:31 AM   #1
LinuxRSA
Member
 
Registered: Apr 2015
Location: South Africa
Posts: 71

Rep: Reputation: Disabled
Script to check User Expiry from a Database using a Container ID


Hi All

I need to create & write a script that displays users about to expire.The expire amount of days is 90 days.

This is how i get the container ID:

Quote:
linux@server-app-04:~$ sudo docker ps -a | grep -i "postgresql" | awk '{print $1}'
[sudo] password for linux:
24acc5d1ec34
linux@server-app-04~$
The idea is to take the container ID 24acc5d1ec34 and then use it in the query to check the database for the user age.

This will in turn provide a list of all users and how old they are in days value, see below.

Quote:
linux@server-app-04:~$ sudo docker exec -i 24acc5d1ec34 psql -h localhost -p 5432 -U dbuser -c "select u.email, now() - to_timestamp(c.created_date/1000)::date password_age from credential c join user_entity u on u.id=c.user_id where now() - to_timestamp(c.created_date/1000)::date > interval '0 days' and c.type='password'" | grep -v "-" | grep -A 5000 -v "email" | grep -v "rows"
support@linuxrsa.ai | 08:18:42.680956
admin@linuxrsa.ai | 113 days 08:18:42.680956
david.goliath@linuxrsa.ai | 77 days 08:18:42.680956
shaun.michaels@linuxrsa.ai | 14 days 08:18:42.680956
How do I write one script to perform both tasks

Not sure if this is right

Quote:
#!/bin/bash
CONTAINER_ID=$(docker ps -a | grep -i "postgresql" | awk '{print $1}')
if [ "$CONTAINER_ID" ]
then
sudo docker exec -i $CONTAINER_ID psql -h localhost -p 5432 -U dbsuer -c "select u.email, now() - to_timestamp(c.created_date/1000)::date password_age from credential c join user_entity u on u.id=c.user_id where now() - to_timestamp(c.created_date/1000)::date > interval '0 days' and c.type='password'" | grep -v "-" | grep -A 5000 -v "email" | grep -v "rows"
Thanks

Last edited by LinuxRSA; 05-06-2022 at 06:04 AM.
 
Old 05-06-2022, 08:15 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Duplicate. Reported
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Analyze And Compare Container Images Using Container-diff LXer Syndicated Linux News 0 12-05-2021 12:33 AM
[SOLVED] Shell Script to extract User account expiry details getraj.12 Programming 3 04-29-2013 11:46 AM
User expiry Script. gsiva Linux - General 13 11-21-2012 09:10 AM
How to monitor certificate expiry date using a linux script jefn Programming 6 04-27-2009 04:37 AM
how to check the password expiry date of a user? binary_0011 Other *NIX 1 06-04-2008 01:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Containers

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration