Sponsored Content
Top Forums Shell Programming and Scripting help with if clause in bash script Post 302468776 by liviusbr on Wednesday 3rd of November 2010 07:35:45 PM
Old 11-03-2010
Hi ,

Thanks, I did that change but still I am getting this error :

./test.bash: line 2: [: too many arguments


What could be wrong ?

---------- Post updated at 01:35 AM ---------- Previous update was at 01:19 AM ----------

Hi,

As I said, I need to count the numbers of DHCP Discovers from the logfile.

Here it is the output :

DHCP01 Test # cat /var/log/messages.2.gz | zgrep 94.18 | grep "DHCPDIS" | grep 0012CFCDA11A | cut -c7- | cut -d ' ' -f5 | sort | uniq -c


3 010012CFCDA11A:

Here is one sample of a line in messages.2.gz :

Nov 3 17:01:04 dhcp01 ZEMdhcp: 010012CFCDA11A: Got DHCPDISCOVER xid=0x545e01bc from 0.0.0.0 via 94.18.124.1, req-ip=None, 82=(0012CFCDA11A ,576F6F1E1201, '94.18.124.6').



So, basically, it counts the number of DHCP discovers for this mac address.

Next, I want to create a script to put the output results in a file. If the command cannot find any discover for a mac address, the output should look like

0 010012CFCDA11A:



The script that I created looks like this :


cat /var/log/messages.2.gz | zgrep 94.18 | zgrep "DHCPDIS" | grep 10012CFCDA11A | cut -c7- | cut -d ' ' -f5 | sort | uniq -c >> /my_scripts/LOGS/dhcp_test

if [ " cat /var/log/messages.2.gz | zgrep 94.18 | grep "DHCPDIS" | grep 10012CFCDA11A | cut -c7- | cut -d ' ' -f5 | sort | uniq -c " -lt "1" ];
then
echo "0 10012CFCDA11A" >> /my_scripts/LOGS/dhcp_test
fi


Thanks,

Last edited by liviusbr; 11-03-2010 at 08:50 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

building a SET clause in shell script

Hi, I have a comma delimited string, e.g. empno, ename, sal. Using Korn Shell Script I want to build the SET clause for an UPDATE statement, and set clause should look like this: empno=decode(:empno, '?', empno, :empno), ename=decode(:ename, '?', empno, :ename), sal=decode(:sal, '?',... (14 Replies)
Discussion started by: shalua
14 Replies

2. UNIX for Dummies Questions & Answers

if clause

hi, pls could you help me with one program in KSH ( i have sunOS). I need to create an If clause, that prints an error message and filenames, when in a directory are found some files of null size (find . -type f -size 0 ). thanks (3 Replies)
Discussion started by: palmer18
3 Replies

3. Shell Programming and Scripting

Bash-Shell: If-Clause to check if file is empty

Hello, I want to checkl whether my file has text in it or not. if ; then ... if ; then ... But none of these work Can someone help me? ---------- Post updated at 09:00 AM ---------- Previous update was at 08:55 AM ---------- The code-tags caused an displayerror,... (5 Replies)
Discussion started by: ABE2202
5 Replies

4. Shell Programming and Scripting

Check a variable value through if clause

Hi guys, I am trying to check the values i have for two variables. if && ; then echo "Success"; fi Now Test1 can have any Alpha Variable and Count is a integer value. Even though we have given 'and' Condition, even one condition is sucess, i am getting the Success message. ... (11 Replies)
Discussion started by: mac4rfree
11 Replies

5. Shell Programming and Scripting

If clause in perl

HI friends , I am very new to perl .please dont mind if i ask silly questions. I seee below code in one sript if ( exists $ENV{FMTWRP_TMP_DIR} and $ENV{FMTWRP_TMP_DIR} ) { $tdir = $ENV{FMTWRP_TMP_DIR}; } whats does this mean . I am very confused about the if clauses in... (1 Reply)
Discussion started by: ptappeta
1 Replies

6. Shell Programming and Scripting

../ in perl and if clause

Hi can anyone please explain what the below code does? i mean $fide_stopfile = ? when $FIDE_SCR = '/fs/dir1/dir2/common/scr' and also little confused with if clause too. what it check? $fide_stopfile = "$ENV{FIDE_SCR}/../tmp/STOP"; if ( -e $fide_stopfile > 0 ) { ... (3 Replies)
Discussion started by: ptappeta
3 Replies

7. Shell Programming and Scripting

Generating & executing the SELECT and UPDATE clause dynamically using shell script

Hi All, I need to write one shell script. The requirement is as follows. a) I am having list the employee names in a file stored in /tmp directory location as below /tmp/emp.txt b) and the contents are as below cat emp.txt ravi raj ram arun c) I need to connect to sybase... (1 Reply)
Discussion started by: Gowtham_giri
1 Replies

8. Shell Programming and Scripting

Oracle 11g script read from file in where clause (RHEL 5.7)

Hi everyone, Simple question. I have a comma-delimited file, aux.txt, with the following contents (all in one line): 'value1','value2','value3',...,'valueN' I would like to know if there's a way I can use that file inside a sql script in a where clause, like so: select myfield1 from mytable... (6 Replies)
Discussion started by: gacanepa
6 Replies

9. Shell Programming and Scripting

If clause query

Hi, i need to add a condition in my IF clause where i need to check if the file exists in a folder and return true out of it. but in my directory i have multiple files with same name but datestamp append on it for e.g. export f1 = filename export f2=filename1 if ] then echo "No... (9 Replies)
Discussion started by: rohit_shinez
9 Replies

10. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 05:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy