[Solved] Date as Input | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

[Solved] Date as Input

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-21-2013
Padmanabhan Padmanabhan is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 12 September 2013, 7:05 AM EDT
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
[Solved] Date as Input

Below is my Scenario.

I wrote one script to search the specific log files for Yesterdays date and gives the result.

I need a script like

1. Once I run the Script, The script should ask me which date I want to search.

2. Once i enter the date, That script should search the log files for a given date and has to gives the result.


Below is my sample script which automattically collect the Yesterdays data


Code:
grep -n processed: /var/Messages/datalogs | grep -n "$( date -d '1 day ago' +'%Y-%m-%d' )"

Please help me in this



Sorry For my English
Sponsored Links
    #2  
Old 02-21-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 24 October 2014, 12:11 PM EDT
Location: India
Posts: 1,831
Thanks: 25
Thanked 525 Times in 504 Posts
Like this?

Code:
#! /bin/bash
echo "Enter date: "
read date
grep -n Processed: /var/messages/datalogs | grep -n "$date"

The Following User Says Thank You to balajesuri For This Useful Post:
Padmanabhan (02-21-2013)
Sponsored Links
    #3  
Old 02-21-2013
Padmanabhan Padmanabhan is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 12 September 2013, 7:05 AM EDT
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
It worked.. Thanks
    #4  
Old 02-21-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 24 October 2014, 12:11 PM EDT
Location: India
Posts: 1,831
Thanks: 25
Thanked 525 Times in 504 Posts
IMHO, that requirement has no real value-add. The only thing that script does is, take date as input and uses it in the grep command. You could actually type the grep one-liner with required date on the command line itself.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] Replace yesterday date with today's date except from the first line Lilu_CK Shell Programming and Scripting 3 12-03-2012 01:44 PM
[Solved] How to refer to input file in code? legato22 UNIX for Dummies Questions & Answers 5 11-14-2012 03:03 PM
[SOLVED] No INPUT chain on nat table in iptables Narnie UNIX for Advanced & Expert Users 0 11-03-2011 04:20 PM
Append file based upon user input-- solved DC Slick Shell Programming and Scripting 0 02-16-2011 06:07 AM
Standard error output to Pipe input - solved poova UNIX for Dummies Questions & Answers 2 02-22-2010 12:56 AM



All times are GMT -4. The time now is 07:51 PM.