Grep Script Prompting question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep Script Prompting question
# 1  
Old 05-03-2011
Grep Script Prompting question

I saw this wonderful script in a previous post and modified it to work, my question is
is there a way to enable a prompt at the GREP portion to allow me to enter what I wish to grep before hand?
Code:
#!/bin/sh

DATE=`date +%Y%m%d%H%M%S`
HOME=/u/home/xxx/report
LOG_DIR=/var/log/
CONSOLE_FILE=ncolog
ALERTS_FILE=report
CONSOLE_OUTPUT=/u/home/xxx/console
ALERTS_OUTPUT=/u/home/xxx/alerts

cd $LOG_DIR

tail -f $CONSOLE_FILE > $CONSOLE_OUTPUT &

grep -i "PROMPT!" $CONSOLE_FILE > $CONSOLE_OUTPUT

a=`ls -lrth $CONSOLE_OUTPUT |awk '{print$5}'`

if [ $a -eq 0 ];
then
     echo "The file is empty"
else
     echo "The Vaule of A differs, please check"
     #/usr/bin/printf "*****  NVC ALERT - $DATE *****\n\nHost: `hostname` \n\nDATE: `date` \n\n" | /bin/mailx -s "Error $DATE  " amil@ex
fi

exit 0

Moderator's Comments:
Mod Comment Please use code tags
# 2  
Old 05-03-2011
I would imagine you can just throw a prompt in there...

Code:
 
echo "What would you like to search for?"
read inputValue
 
grep -i "$inputValue" $CONSOLE_FILE > $CONSOLE_OUTPUT

I don't see any reason why it wouldn't work. Didn't test, just throwing it out there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run sftp in shell script without prompting for password?

Hi, Can anyone tell me how to pass password in a shell script for sftp so that i can run it in background without user entering the password? I used a expect script but it timesout after some time and the process remains incomplete at the end. Can anyone suggest any other idea? Will the... (3 Replies)
Discussion started by: Little
3 Replies

2. Shell Programming and Scripting

Prompting user twice on the same line

Hi, I'm trying to prompt twice on the same line but can't make it so far. I can prompt only once per line. i.e. read -p "Enter the two digits of your sum: " NUM1; read -p "+" NUM2 the result of above is:Enter the two digits of your sum: 5 + 7 But I would like it to look something... (8 Replies)
Discussion started by: violeta.barajas
8 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

SFTP prompting for password even though password is in script

Hi All, I am trying to transfer a file from one server to a remote server using SFTP. Client is not ready for key setup. I am working on Solaris 10. Here is the code. #!/bin/ksh # sample automatic Sftp script to dump a file USER="user1" PASSWORD="pass1" HOST="host1" sftp $USER@$HOST... (6 Replies)
Discussion started by: megha2525
6 Replies

5. Shell Programming and Scripting

Prompting for password

Hi, I have SVN installed in my UNIX solaris server. I actually automated the process that downloads code from SVN server to UNIX solaris server in script. When i run the script, its asking for password to download every element. Its really difficult to type password for every element when... (3 Replies)
Discussion started by: gthangav
3 Replies

6. Shell Programming and Scripting

running a script using su - without prompting password

hi guys, is there any way to run a script using su - without prompting a password? ex: su - $APPSUSERNAME/$APPSUSERPASSWORD stop_apps.sh my purpose here is to run a script with current dbuser. thanks in advance. (3 Replies)
Discussion started by: d3xt3r
3 Replies

7. UNIX for Advanced & Expert Users

scp without prompting for password

I am trying to copy a file from remote machine using scp. I followed the steps to configure public/private key usage. But still prompting for password when I do ssh. I did the following steps to configure scp without asking password Step 1 : local host > ssh-keygen -t rsa and when prompted... (9 Replies)
Discussion started by: satish@123
9 Replies

8. Shell Programming and Scripting

New Unix user with shell script question using grep

Hello, I am a new Unix user and new to shell programming. I am working on a script to go through a log file and find the text error: grep -i 'error' monplus.mplog if I find the text error in the log file I would like to echo a message to the operator staing there is an error I am currently... (2 Replies)
Discussion started by: dtracy01
2 Replies

9. UNIX for Advanced & Expert Users

SSH - Prompting for password

Hi, Can anybody tell me a way to do ssh , without prompting for password from keyboard, Using RSA. The requirement is I need to create the key , using passphrase also..... Is there any way to do it in UNIX ? I am doing it from AIX machine , but remote machine is Linux I tried... (8 Replies)
Discussion started by: shihabvk
8 Replies

10. UNIX for Dummies Questions & Answers

not script prompting but,.............

Hi, I am writig this script and usually I have prompts like: echo "Enter file name: " read "$filename" So later when I want verify the name to something I can: if then echo "Hello $filename" Anyways how is this done without prompting for example: I have a script that manages... (3 Replies)
Discussion started by: Astudent
3 Replies
Login or Register to Ask a Question