LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2021, 11:17 PM   #1
Neljor
LQ Newbie
 
Registered: May 2020
Location: Seattle, US
Distribution: OpenSuSE
Posts: 21

Rep: Reputation: Disabled
Bash scripting


Made this simple script, but it does not work.

Code:
#! /bin/bash
  
DAY=$(date | awk '{print $1,$2,$3}')

echo "List of the packages installed today $DAY:"
 rpm -qa --queryformat '%{NAME} was installed on %{INSTALLTIME:date}\n' | grep $DAY

exit $0
Any suggestions how this should be done?
Thanks in advantage!

Peter
 
Old 03-16-2021, 12:18 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,244

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Code:
grep $DAY
should be

Code:
grep "$DAY"
ShellCheck would have told you that.

The "exit" line is both wrong ("$0" is the name of the script) and unnecessary. I assume you mean "exit 0", which is redundant.
 
1 members found this post helpful.
Old 03-16-2021, 12:29 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

Code:
DAY=$(date +'%b %e [0-9][0-9]:[0-9][0-9]:[0-9][0-9] %Y')
rpm -qa --queryformat '%{NAME} was installed on %{INSTALLTIME:date}\n' | grep -E "$DAY"
Probably just the quotes around "$DAY" will make it work.
The other fix change is to match year, month and day of month.

Evo2.

N.B. I couldn't find any documentation on how the date string from the rpm command is formatted. If it changes with the locale you could find yourself with an additional problem.

Last edited by evo2; 03-16-2021 at 12:32 AM. Reason: N.B.
 
1 members found this post helpful.
Old 03-16-2021, 02:34 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,967

Rep: Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332
this is the best I could find: http://www.l3jane.net/doc/soft/max-r...ery-parts.html
and this: http://lists.rpm.org/pipermail/rpm-l...il/001122.html
 
Old 03-16-2021, 04:38 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
I couldn't find any documentation on how the date string from the rpm command is formatted.
From the rpm manual page:
Quote:
:date
Use strftime(3) "%c" format.
:day
Use strftime(3) "%a %b %d %Y" format.

Quote:
Originally Posted by evo2 View Post
If it changes with the locale you could find yourself with an additional problem.
Yep, it's locale dependent when using :date or :day type tags (though the :day output has fixed format sequence %a %b %d %Y as per above)
Code:
$ rpm -q rpm --qf '%{n}: %{installtime}\n'
rpm: 1607559087
$ LC_ALL=de_DE rpm -q rpm --qf '%{n}: %{installtime:day}\n'
rpm: Do Dez 10 2020
$ LC_ALL=C rpm -q rpm --qf '%{n}: %{installtime:day}\n'
rpm: Thu Dec 10 2020

Last edited by shruggy; 03-16-2021 at 04:51 AM.
 
1 members found this post helpful.
Old 03-16-2021, 11:39 AM   #6
Neljor
LQ Newbie
 
Registered: May 2020
Location: Seattle, US
Distribution: OpenSuSE
Posts: 21

Original Poster
Rep: Reputation: Disabled
Thumbs up Rpm query script

Thank you all for the replies, very helpful

Have changed the script in this:

Code:
#! /bin/sh
  
LC_ALL=C
DAY=$(date +'%a %b %d %Y')

echo "List of the packages installed today $DAY:"
 rpm -qa --queryformat '%{NAME} was installed on %{INSTALLTIME:day}\n' | grep -E "$DAY"

exit 0

Last edited by Neljor; 03-16-2021 at 12:17 PM. Reason: Additional info
 
  


Reply

Tags
bash script



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
Bash Scripting – Code Structure - Defining Multiple Points Of Entry In Bash Script carlr Programming 10 08-25-2014 02:38 AM
[To share Bash knowledge]Notes for Advanced Bash-Scripting Version 10 (Latest) jcky Programming 4 07-31-2014 09:24 AM
LXer: Bash If statements, Exit Status and Comparison Operators, A beginners guide to bash scripting LXer Syndicated Linux News 0 06-29-2014 07:35 PM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:09 PM.

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