Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Why does this not work in a script?

Options
  • 16-04-2008 9:25am
    #1
    Registered Users Posts: 5,580 ✭✭✭


    Hi all. Is there any reason why when i run the command in bold from command line, that it works fine. However, in the script it outputs the following...

    monitor.sh: /home/erayfra/log: bad number


    #!/bin/sh

    touch /home/erayfra/log
    sh /home/erayfra/stuff.sh 360 INT tail -f /var/opt/ericsson/oss_data/150408/all.
    events >& /home/erayfra/log

    PEAKS=`cat /home/erayfra/log | grep -v Freq | grep -c peak`
    date >> /home/erayfra/log.log
    echo "You have $PEAKS peaks. You should have 9000" >> /home/erayfra/log.log
    rm /home/erayfra/log


    Can you suggest corrections? :pac:


Comments

  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    Hey, try:


    events >> /home/erayfra/log


    you alrady created the log file with touch


  • Registered Users Posts: 5,580 ✭✭✭veryangryman


    erayfra@atrcus145:~$ sh monitor.sh
    tail: cannot open input


    No joy. Thanks for trying though - keep sugestions coming


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    the reason for it running in your shell and not in the script is that your shell is most likely ignoring the '&' misuse.

    switch to the Korn shell:
    sh

    Then run your command:
    events >& /home/erayfra/log

    and you'll see the same error.


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    erayfra@atrcus145:~$ sh monitor.sh
    tail: cannot open input


    No joy. Thanks for trying though - keep sugestions coming

    does the file "/var/opt/ericsson/oss_data/150408/all." exist? note you have a . at the end.


  • Registered Users Posts: 5,580 ✭✭✭veryangryman


    Thats spread over 2 lines on these forums.:( Its actually one line in the script. So its all.events


  • Advertisement
  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    also bear in mind the "tail -f <file>" command will loop endlessly untill you kill it, that is if the file exists.


  • Registered Users Posts: 5,580 ✭✭✭veryangryman


    The stuff.sh script sorts that out. The number 360 is the number of seconds that the stuff script sleeps for before killing the tail process


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    ok well make sure that file:
    /var/opt/ericsson/oss_data/150408/all.events
    exists:

    ls -l /var/opt/ericsson/oss_data/150408/all.events


  • Registered Users Posts: 868 ✭✭✭brianmc


    the reason for it running in your shell and not in the script is that your shell is most likely ignoring the '&' misuse.

    switch to the Korn shell:
    sh

    Then run your command:
    events >& /home/erayfra/log

    and you'll see the same error.

    I believe Treasure Wailing Celebration is on the right track here.

    A lot of places use csh or tcsh on the command line where the >& redirection allows you to redirect both ordinary and error output to a file.

    I the bourne style shells >& allows you to redirect standard output only to another file descriptor... i.e. >&2

    A file descriptor is a number hence the "bad number" error message.

    I suspect the line you need for your script should be...
    sh /home/erayfra/stuff.sh 360 INT tail -f /var/opt/ericsson/oss_data/150408/all.events > /home/erayfra/log 2>&1
    


Advertisement