Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Need some help writing this script..

    Hi guys,
    Joined this forum ages ago, but I'm still a linux newbie. I have to use ubuntu at work so now I come crawling back for help..

    Basically I'm working with a large C++ application that takes several command line arguments. Each time the application runs a log file is created. There is a certain number that is in the log file at a predefined location that is of interest to me.

    I need some way of (1) automatically running the application with different command line args, (2) opening the logfile and parsing its contents for this particulat number and (3) closing and deleting the log file, and repeating (1)

    I have no idea where to start.. if someone could help me with (1) I could possibly figure out (2) for myself..

    Thank you a lot

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Tokyo, Japan
    1) when you say run the application automatically, do you mean run the application at a given point in time(for example run the application every monday at 12)?
    if that is the case you can use it as a cron job and that will do it.
    if that is not what you want please be more specific

    for this one many tools exist and you can choose one depending on what you want to do.
    man sed
    man awk
    man grep
    Linux and me it's a love story

  3. #3
    No sorry what I mean by automatically is to run it x times in succession without manually putting in the arguments each time..
    But the actual script can be run manually.
    So obviously it would have to let the program run, then terminate, then parse the file, then run again, etc..

    A simplistic example would be:
    for (int arg=0; arg<12; arg++)
    ./program arg

    I will look into the tools you mentioned, thanks a lot for the reply.

    EDIT: I had a look at those manuals.. couldn't really make a whole lot of sense out of them, but thanks anyway

  4. $spacer_open
  5. #4
    Well I just wrote a c program to do it... but I still need a script to glue it all together..

    Can someone please tell me why this doesn't work?

    My args are the strings below (args1, args2...)
    I'm trying to loop through 1 to whatever using index i and then concatenate the word args with the symbol i toi get me "argsi" (e.g. args1), then use $ to get the value of args1 and feed it into the program args..


    args1="40 9 trinity.xml trinityphases.xml 1 10 20 2"
    args2="40 9 trinity.xml trinityphases.xml 2 10 20 2"

    for i in $(seq 1 2); do
    echo "Running script: "$args{i}""
    ./perSim $args
    ./nbcarsarrived $args

    echo "Done...\n"

  6. #5
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Tokyo, Japan
    it is quite tricky in shell scripting to loop over variable.
    you can use bash arrays ,put the arugments in them and then use the array .
    for bash arrays usage check this out.
    Linux and me it's a love story

  7. #6
    Sweet, got it all working now.. thanks for the help..

  8. #7
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Tokyo, Japan
    glad to know that you got it working
    Linux and me it's a love story

Posting Permissions

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