Find the answer to your Linux question:
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.
  1. #1
    Just 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

  2. #2
    Linux Enthusiast
    Join Date
    Jun 2002
    Location
    San Antonio
    Posts
    621
    Ah, the old-school bashisms come back quickly. Spacing matters!

    Code:
    if ['grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l' -eq 5]; then
    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.

    Best,

    Samuel
    I respectfully decline the invitation to join your delusion.

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42
    Quote Originally Posted by wassy121
    Ah, the old-school bashisms come back quickly. Spacing matters!

    Code:
    if ['grep "$PATTERN" /mnt/etr/wt01/Logs/wt01-20041125.log | wc -l' -eq 5]; then
    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.

    Best,

    Samuel
    Hey When I run this I get nothing out it, it is just staying there plus i get this

    -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

  4. #4
    Just 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.

  5. #5
    Linux 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

  6. #6
    Linux 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,

    Samuel
    I respectfully decline the invitation to join your delusion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •