Results 1 to 6 of 6
I am getting the follwong error when I run this shelll script
bash: [grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l: No such file or directory
It is not true what they ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-27-2004 #1Just Joined!
- Join Date
- Aug 2004
- Posts
- 42
shell scripts error
I am getting the follwong error when I run this shelll script
bash: [grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l: No such file or directory
It is not true what they say 'No such file or directory " I know that whole directory exists. So please I need help on this
#!/bin/bash
$PATTERN="2014280766"
while true; do
if ['grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l' -eq 5]; then
printf 'To:kumar@localhost\nThings went bad' | /usr/sbin/sendmail -t
fi
done
This what I want to do though??
If you want to monitor /mnt/etr/wt01/Logs/wt01-20041125.log
and you want to have the computer email you a sorted copy of it when there are hvve lines that match a specipc pattern, you
- 11-27-2004 #2Linux Enthusiast
- Join Date
- Jun 2002
- Location
- San Antonio
- Posts
- 621
Ah, the old-school bashisms come back quickly. Spacing matters!
is wrong. It should read:Code:if ['grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l' -eq 5]; then
Note that I changed the single-quotes to backticks, and added a space between each square bracket. That should work nicely.Code:if [ `grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l` -eq 5 ]; then
Best,
SamuelI respectfully decline the invitation to join your delusion.
- 11-27-2004 #3Just Joined!
- Join Date
- Aug 2004
- Posts
- 42
Hey When I run this I get nothing out it, it is just staying there plus i get this
Originally Posted by wassy121
-bash: !/bin/bash: event not found, Could you please tell me how excute the shell scripting on the Terminal please
if run without this #!/bin/bash, it doesnt gives me anything it just statying there.
Thanks
Code:#!/bin/bash PATTERN="1100601032" while true; do if [`grep "$PATTERN" /usr/local/nagios/var/downtime.log | wc -l` -eq 5]; then printf 'To:root@localhost\nThings went bad' | /usr/sbin/sendmail -t fi
- 11-28-2004 #4Just Joined!
- Join Date
- Nov 2004
- Posts
- 17
The script should be saved as something.sh and made executable. Then from a shell you can do ./something.sh
You need the line #!/bin/bash at the top of the script for it to be a shell script, so don't take it out.
- 11-29-2004 #5Linux Newbie
- Join Date
- Apr 2004
- Posts
- 158
Hi,
You also need to put your $PATTERN as PATTERN= and not as $PATTERN=...
Cheers
Jonas--
in Linux Computing we Trust
- 11-29-2004 #6Linux Enthusiast
- Join Date
- Jun 2002
- Location
- San Antonio
- Posts
- 621
Also, the logic is all wrong. The email will only get sent if there are exactly five entries of $PATTERN in the file. But, it will continue to run the grep command over and over and over again (due to the while true).
Best,
SamuelI respectfully decline the invitation to join your delusion.


Reply With Quote
