Sponsored Content
Top Forums UNIX for Dummies Questions & Answers grep pipe filename print issue Post 302544523 by shifahim on Thursday 4th of August 2011 04:57:12 AM
Old 08-04-2011
Error

Quote:
Originally Posted by radoulov
Try this one (untested again):

Code:
find . \( -name '*.cer' -o -name '*.jks' \) -exec bash -c '
  fn=$1 
  [[ $fn == *.cer ]] &&
    _opt="-printcert -file" ||
    _opt="-keystore"      
  keytool -v -list $_opt "$fn" |
    while IFS= read -r; do
      [[ $REPLY == *"Aug 3"* || $REPLY == *Owner* ]] && {
      [[ -n $r ]] && r="$r $REPLY" || r=$REPLY
      (( ++c == 2 )) && {
        printf "%s: \n%s\n" "$fn" "$r"       
        break
        }
    }
    done          
  ' inline {} \;

If you really need a case insensitive search, the pattern should be changed.
It greps for the "Owner" but not for "Aug 03". Needless, I have this as working

Code:
find $1 \( -name '*.cer' -o -name '*.jks' \) -exec bash -c '
  fn=$2
  case $fn in
    ( *.cer ) _opt="-printcert -file" ;;
    ( *.jks ) _opt="-keystore"        ;;
  esac
 echo | keytool -v -list $_opt "$fn" 2> /dev/null|
    egrep -i  "$1|Owner" &&
      printf "%s\n" "$fn"
  ' inline "$2" {} \;

Below is the sample output that i get:
Code:
./certfinder.sh /apps/ "until:"

Owner: OU=www.verisign.com.(c)97 VeriSign, OU=VeriSign CA - Class 3, OU="VeriSign, Inc.", O=VeriSign
Valid from: Sun Jan 30 19:00:00 EST 2011 until: Wed Feb 08 18:59:59 EST 2012
/apps/certs/MQ_clientcerts.jks

However, I need some hint if I wish to check and add to the current output in this format.

if current system date>until: Wed Feb 08 18:59:59 EST 2012 [Expired]
if year is the current year [Expires This year]
if year is current year +1 [Expires Next year]
if year is > current year +1 [Good enough]
Thanks. Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using grep and print filename

Hi, I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files. I have alot files such that a.txt, b.txt,c.txt...etc. If I found a certain character, I would print that particular filename. I... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

2. AIX

Removing a filename which has special characters passed from a pipe with xargs

Hi, On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories. Having said that I am more curious to know how this can be done. an sample... (3 Replies)
Discussion started by: jerardfjay
3 Replies

3. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

4. Shell Programming and Scripting

Filename pattern match and appending pipe

Hi, I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records. I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each... (3 Replies)
Discussion started by: nss280
3 Replies

5. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

6. Shell Programming and Scripting

Diff between grep .* file name and grep '.*' filename

Hi, Can anyone let me know what is difference between grep .* foo.c grep '.*' foo.c I am not able to understand what is exact difference. Thanks in advance (2 Replies)
Discussion started by: SasDutta
2 Replies

7. Shell Programming and Scripting

How to pipe a filename that includes a date?

How do I pipe the output of something to a filename that includes the date, in a specific date format? Here's the goal. Output a script to a file periodically during the day: ./script.sh >>logname_yyyy-mm-dd.logAnd when the next day comes, it starts logging to a new filename because the date... (2 Replies)
Discussion started by: nbsparks
2 Replies

8. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

9. UNIX for Dummies Questions & Answers

Print/cut/grep/sed/ date yyyymmdd on the filename only.

I have this filename "RBD_EXTRACT_a3468_d20131118.tar.gz" and I would like print out the "yyyymmdd" only. I use this command below, but if different command like cut or print....etc. Thanks ls RBD_EXTRACT* | sed 's/.*\(........\).tar.gz$/\1/' > test.txt (9 Replies)
Discussion started by: dotran
9 Replies

10. Shell Programming and Scripting

Space in input filename with pipe

Hello, Normally below script works, could you please comment out what could be the reason of failure if there are spaces in input filename: script.sh #!/bin/bash cd /home/hts/.hts/tvh/ file="$1 $2 $3 $4" read -d $'\x04' name < "$file" /usr/bin/ffmpeg -i ""$name"" -vcodec copy -preset... (1 Reply)
Discussion started by: baris35
1 Replies
sttime(3)						    ShapeTools Toolkit Library							 sttime(3)

NAME
stMktime, stWriteTime - date and time handling SYNOPSIS
#include <config.h> #include <sttk.h.h> time_tstMktime (char *string); char*stWriteTime (time_t date); DESCRIPTION
stMktime scans the given string and tries to read a date and time from it. It understands various formats of date strings. The following is a list of all valid formats, optional parts in brackets. [Tue] Jan 5[,] [19]93 This includes the standard asctime(3) format. Jan 5 With no year given, the year defaults to the current year. [19]93/01/05 This notation requires month and day represented by exactly two digits. 5.1.[19]93 This is the usual German notation. 5.1. German notation referencing the current year. A certain time, given together with the date must always have the following form. hours:minutes[:seconds] Each of the fields must be an integer value within the proper range (hours: 0-23, minutes and seconds: 0-59). Values below 10 may be written as one digit numbers. The time value may be placed anywhere in the date string: at the beginning, at the end, or somewhere in the middle. Any amount of white- space may be given between a field of the time value and the separating colon. The time is always considered to be local time. stWriteTime generates a time string similar to asctime(3) from its date argument. SEE ALSO
asctime(3) BUGS
Time Zone Names within the time string (like `MET') are not handled properly. In most cases they will cause a failure. sttk-1.7 Thu Jun 24 17:43:35 1993 sttime(3)
All times are GMT -4. The time now is 08:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy