Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Why does this not work in a script?

  • 16-04-2008 08:25AM
    #1
    Registered Users, Registered Users 2 Posts: 5,763 ✭✭✭


    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, Registered Users 2 Posts: 5,763 ✭✭✭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, Registered Users 2 Posts: 5,763 ✭✭✭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, Registered Users 2 Posts: 5,763 ✭✭✭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, Registered Users 2 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