[Solved] Date as Input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Date as Input
# 1  
Old 02-21-2013
[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
# 2  
Old 02-21-2013
Like this?
Code:
#! /bin/bash
echo "Enter date: "
read date
grep -n Processed: /var/messages/datalogs | grep -n "$date"

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-21-2013
It worked.. ThanksSmilie
# 4  
Old 02-21-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to get previous date for the given input date..

hi all, need a script or command to get the previous date for the given input date... like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30 (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

2. Shell Programming and Scripting

[Solved] Testing Data Type of User Input

hi all i'm new in shell scripting and now i'm working on project and i wanna make a function take input from user and test it's datatype then if correct write it to file i wounder what is the best way to do this ? can i use awk ? edit by bakunin: Please give your threads a meaningful... (5 Replies)
Discussion started by: mohamed91
5 Replies

3. Shell Programming and Scripting

[Solved] Read and validate input arguments

Hi, I need to get input arguments, as well as validate them. This is how I'm reading them: #!/bin/bash args="$@" # save arguments to variable ## Read input arguments, if so while ; do case $1 in -v | --verbose ) verbose=true;; -z | --gzip ) compression="gz";; ... (3 Replies)
Discussion started by: AlbertGM
3 Replies

4. Shell Programming and Scripting

Get yesterdays Date for Input Date

Hi, I have been trying to get the yesterdays date for the Input date I pass. I know how to do for the current timestamp but how to do for the input date. Is there any way I can convert to epoch time and do manipulations and back to human readable date? Please help Thanks ... (1 Reply)
Discussion started by: abhi1988sri
1 Replies

5. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

6. UNIX for Dummies Questions & Answers

[Solved] How to refer to input file in code?

This may be a dumb question, but googling is not giving me an answer. I'm trying to figure out how to refer to an input file in my code. Lets say i run a script in bash: "sh shellscript.sh inputfile" (Inputfile will be variable...whatever file i run the script on) I wanted to make... (5 Replies)
Discussion started by: legato22
5 Replies

7. UNIX for Advanced & Expert Users

[SOLVED] No INPUT chain on nat table in iptables

Hello, I'm having problem with an iptables rule. It seems that on one of two systems on the nat table, the INPUT chain doesn't exist for some strange reason. I get the error below: # iptables -t nat -A INPUT -j ACCEPT iptables: No chain/target/match by that name. Here is my kernel on... (0 Replies)
Discussion started by: Narnie
0 Replies

8. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

9. UNIX for Dummies Questions & Answers

Standard error output to Pipe input - solved

Hi, I want to check a particular word is in standard error output or not. Can I acheive it in single command? For example, Delete file_name 2>error.log cat error.log Output: XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX Successfully deleted XXXXXXXXXXXXXXXXX where delete is... (2 Replies)
Discussion started by: poova
2 Replies

10. Shell Programming and Scripting

Get date range between 2 date input

Hi Experts, I have files name report_20090416 report_20090417 report_20090418 report_20090420 report_20090421 I have 2 input from user From Date: 20090417 To Date: 20090420 and I need to grep only those line in between. Output should be report_20090417 report_20090418... (3 Replies)
Discussion started by: tanit
3 Replies
Login or Register to Ask a Question