Thread: calling sac commands within shell scripts

Started: 2010-10-25 19:20:41
Last activity: 2010-10-30 14:02:23
Topics: SAC Help
Geo .
2010-10-25 19:20:41
Greetings,
I am trying to call sac within a shell script as follows.

while read line
do
cd $line

sac
gawk '{print "macro ../sac_cut.macro"}'

cd ../
done < folder_list.txt


folder_list.txt holds the names of all the directory names that the script
is suppose to look in.
I see that sac is initiated but the problem is in executing commands within
sac once it is initiated. I have tried several ways of doing that including
printf and piping to sac with back quotes. Still I get the following error.

SAC> readline: readline_callback_read_char() called with no handler!

How should one execute sac commands within a shell script?

I am using sac Version 101.3b

Thanks a lot.

Januka.

  • Derek Schutt
    2010-10-25 17:31:17
    Hi Januka,

    Here's one way to do it. This is from a bash script that invokes sac
    to change the "a" and "f" headers:

    echo -e "r $sacfile \n ch a $a_time \n ch F $F_time \n wh \n exit" | sac

    I'd bet there are much more elegant ways to do it too.

    -Derek


    On 10/25/2010 10:20 AM, Januka Attanayake wrote:
    Greetings,
    I am trying to call sac within a shell script as follows.

    while read line
    do
    cd $line

    sac
    gawk '{print "macro ../sac_cut.macro"}'

    cd ../
    done < folder_list.txt


    folder_list.txt holds the names of all the directory names that the
    script is suppose to look in.
    I see that sac is initiated but the problem is in executing commands
    within sac once it is initiated. I have tried several ways of doing
    that including printf and piping to sac with back quotes. Still I get
    the following error.

    SAC> readline: readline_callback_read_char() called with no handler!

    How should one execute sac commands within a shell script?

    I am using sac Version 101.3b

    Thanks a lot.

    Januka.


    _______________________________________________
    sac-help mailing list
    sac-help<at>iris.washington.edu
    http://www.iris.washington.edu/mailman/listinfo/sac-help


    --
    --------------------
    Derek Schutt
    Assistant Professor
    Geosciences Department
    309 Natural Resources Building
    Campus Delivery 1482
    Fort Collins, CO 80525-1482
    http://warnercnr.colostate.edu/~schutt/CSU_web/index.htm
    970-491-5786


    • Januka Attanayake
      2010-10-25 16:50:03
      Thanks Derek, I modified your command line as

      echo -e "macro ../sac_cut.macro \n exit" | sac

      and still get the same error:
      SAC> readline: readline_callback_read_char() called with no handler!
      Aborted (core dumped)
      cd: 25: can't cd to sac_cut.macro

      I am thinking macro isn't seen as a command within sac by echo.

      Thanks again!

      Serenity isn't freedom from the storm, but peace within the storm
      Januka Attanayake  Global Seismology & Economics
      The University of Connecticut
      Beach Hall - U2045
      354, Mansfield Rd;
      Storrs, CT 06269
      Tel :  860 486 0475 (Office)
                860 486 3914 (Lab - P405)
      URL: http://sites.google.com/site/janukaattanayake/






      --- On Mon, 10/25/10, Derek Schutt <Derek.Schutt<at>colostate.edu> wrote:

      From: Derek Schutt <Derek.Schutt<at>colostate.edu>
      Subject: Re: [SAC-HELP] calling sac commands within shell scripts
      To: sac-help<at>iris.washington.edu, jattanayake<at>gmail.com
      Date: Monday, October 25, 2010, 12:31 PM






      Hi Januka,



      Here's one way to do it.   This is from a bash script that invokes
      sac to change the "a" and "f" headers:



      echo -e "r $sacfile \n ch a $a_time \n ch F $F_time \n wh \n exit" |
      sac



      I'd bet there are much more elegant ways to do it too.  



      -Derek





      On 10/25/2010 10:20 AM, Januka Attanayake wrote:
      Greetings,

      I am trying to call sac within a shell script as follows.



      while read line

      do

          cd $line

        

              sac

              gawk '{print "macro ../sac_cut.macro"}'



          cd ../

      done < folder_list.txt





      folder_list.txt holds the names of all the directory names that
      the script is suppose to look in.

      I see that sac is initiated but the problem is in executing
      commands within sac once it is initiated. I have tried several
      ways of doing that including printf and piping to sac with back
      quotes. Still I get the following error.



      SAC> readline: readline_callback_read_char() called with no
      handler!



      How should one execute sac commands within a shell script?



      I am using sac Version 101.3b



      Thanks a lot.



      Januka.


      _______________________________________________
      sac-help mailing list
      sac-help<at>iris.washington.edu
      http://www.iris.washington.edu/mailman/listinfo/sac-help






      --
      --------------------
      Derek Schutt
      Assistant Professor
      Geosciences Department
      309 Natural Resources Building
      Campus Delivery 1482
      Fort Collins, CO 80525-1482
      http://warnercnr.colostate.edu/~schutt/CSU_web/index.htm
      970-491-5786



      -----Inline Attachment Follows-----

      _______________________________________________
      sac-help mailing list
      sac-help<at>iris.washington.edu
      http://www.iris.washington.edu/mailman/listinfo/sac-help




  • Hi again,
    I've had a couple of responses from the members, thanks for your time!
    However, none of them worked. I still get the same error. I am calling sac
    within a while read line loop. Should there be a special way of calling sac
    and executing commands if I do it in a loop? I haven't come across this
    problem with other programs like GMT and taup at all.

    my error msg: SAC> readline: readline_callback_read_char() called with no
    handler!

    and bash script:

    while read line
    do
    cd $line

    sac
    gawk '{print "macro ../sac_cut.macro"}'

    cd ../
    done < folder_list.txt

    commands I've tried so far:

    (1) echo -e "macro ../sac_cut.macro" | sac

    (2) sac << EOF and !
    macro ../sac_cut.macro
    EOF and ! ==> doesn't work within a while loop

    (3) printf "macro ../sac_cut.macro" | sac
    (4) echo "macro ../sac_cut.macro" | sac


    Thanks again !

    Januka.

    On Mon, Oct 25, 2010 at 12:20 PM, Januka Attanayake
    <jattanayake<at>gmail.com>wrote:

    Greetings,
    I am trying to call sac within a shell script as follows.

    while read line
    do
    cd $line

    sac
    gawk '{print "macro ../sac_cut.macro"}'

    cd ../
    done < folder_list.txt


    folder_list.txt holds the names of all the directory names that the script
    is suppose to look in.
    I see that sac is initiated but the problem is in executing commands within
    sac once it is initiated. I have tried several ways of doing that including
    printf and piping to sac with back quotes. Still I get the following error.

    SAC> readline: readline_callback_read_char() called with no handler!

    How should one execute sac commands within a shell script?

    I am using sac Version 101.3b

    Thanks a lot.

    Januka.




    --
    "Nothing can start to exist nor can cease to exist, only transformation is
    possible"

    Januka Attanayake
    Solid Earth Geophysics & Economics
    University of Connecticut
    Beach Hall U-2045
    354,Mansfield Rd;
    Storrs.CT 06269

    Tel: +1 860 486 0475 (Office)
    +1 860 486 3914 (Lab - P405)
    URL: http://sites.google.com/site/janukaattanayake/

    • Onur Tan
      2010-10-26 04:45:29
      Hi ,

      This Cshell script may run (I cannot test at this time) .

      the file a.csh :
      ----
      foreach dir ( ` cat folder_list.txt ` ) # note that there two backquotes

      cd $dir
      echo macro ../sac_cut.macro > macro.tmp # the last line of the sac_cut.macro must be ‘exit’ to quit from sac
      sac < macro.tmp
      cd ..

      end
      \rm tmp
      ----

      to run type
      csh a.csh



      Dr. Onur TAN
      ---------------------------------------------- 40.7866N 29.4500E ---------
      TÜBİTAK Marmara Araştırma Merkezi, Yer ve Deniz Bilimleri Enstitüsü
      TUBITAK Marmara Research Center, Earth and Marine Sciences Institute
      Gebze - Kocaeli - TURKEY




      On 25.10.2010 21:21, "Januka Attanayake" <jattanayake<at>gmail.com> wrote:

      Hi again,
      I've had a couple of responses from the members, thanks for your time! However, none of them worked. I still get the same error. I am calling sac within a while read line loop. Should there be a special way of calling sac and executing commands if I do it in a loop? I haven't come across this problem with other programs like GMT and taup at all.

      my error msg: SAC> readline: readline_callback_read_char() called with no handler!

      and bash script:

      while read line
      do
      cd $line

      sac
      gawk '{print "macro ../sac_cut.macro"}'

      cd ../
      done < folder_list.txt

      commands I've tried so far:

      (1) echo -e "macro ../sac_cut.macro" | sac

      (2) sac << EOF and !
      macro ../sac_cut.macro
      EOF and ! ==> doesn't work within a while loop

      (3) printf "macro ../sac_cut.macro" | sac
      (4) echo "macro ../sac_cut.macro" | sac


      Thanks again !

      Januka.

      On Mon, Oct 25, 2010 at 12:20 PM, Januka Attanayake <jattanayake<at>gmail.com> wrote:
      Greetings,
      I am trying to call sac within a shell script as follows.

      while read line
      do
      cd $line

      sac
      gawk '{print "macro ../sac_cut.macro"}'

      cd ../
      done < folder_list.txt


      folder_list.txt holds the names of all the directory names that the script is suppose to look in.
      I see that sac is initiated but the problem is in executing commands within sac once it is initiated. I have tried several ways of doing that including printf and piping to sac with back quotes. Still I get the following error.

      SAC> readline: readline_callback_read_char() called with no handler!

      How should one execute sac commands within a shell script?

      I am using sac Version 101.3b

      Thanks a lot.

      Januka.




    • Pablo Palacios
      2010-10-30 14:02:23

      Hi all,

      Frequently I have used this instruction within or not of a loop:

      sac << EOF
      macro ../sac_cut.macro
      EOF

      EOF (end of file, or what ever other string) is used to identify or close the end of sac (or other program like matlab or R) intructions. Between sac<<EOF and EOF you can put sac instructions. But you must care dont put space or tabs before the onset of each line, usually done when we put code within a loop. If EOF has, for instance, 3 spaces before EOF, the open intruction of sac must have them:

      sac << EOF

      macro ../sac_cut.macro

      EOF

      I am using cshell. I have not tested in other type of shell. If you dont want echo of the process you can use this:

      sac << EOF>/dev/null

      macro ../sac_cut.macro

      EOF

      If you want extract results to a file:

      sac << EOF>my.file


      macro ../sac_cut.macro


      EOF

      regards,
      P.


      Date: Mon, 25 Oct 2010 14:21:44 -0400
      From: jattanayake<at>gmail.com
      To: sac-help<at>iris.washington.edu
      Subject: Re: [SAC-HELP] calling sac commands within shell scripts

      Hi again,
      I've had a couple of responses from the members, thanks for your time! However, none of them worked. I still get the same error. I am calling sac within a while read line loop. Should there be a special way of calling sac and executing commands if I do it in a loop? I haven't come across this problem with other programs like GMT and taup at all.


      my error msg: SAC> readline: readline_callback_read_char() called with no handler!

      and bash script:

      while read line
      do
      cd $line

      sac
      gawk '{print "macro ../sac_cut.macro"}'


      cd ../

      done < folder_list.txt

      commands I've tried so far:

      (1) echo -e "macro ../sac_cut.macro" | sac

      (2) sac << EOF and !
      macro ../sac_cut.macro
      EOF and ! ==> doesn't work within a while loop


      (3) printf "macro ../sac_cut.macro" | sac
      (4) echo "macro ../sac_cut.macro" | sac


      Thanks again !

      Januka.

      On Mon, Oct 25, 2010 at 12:20 PM, Januka Attanayake <jattanayake<at>gmail.com> wrote:

      Greetings,
      I am trying to call sac within a shell script as follows.

      while read line

      do
      cd $line

      sac
      gawk '{print "macro ../sac_cut.macro"}'

      cd ../

      done < folder_list.txt


      folder_list.txt holds the names of all the directory names that the script is suppose to look in.
      I see that sac is initiated but the problem is in executing commands within sac once it is initiated. I have tried several ways of doing that including printf and piping to sac with back quotes. Still I get the following error.



      SAC> readline: readline_callback_read_char() called with no handler!

      How should one execute sac commands within a shell script?

      I am using sac Version 101.3b

      Thanks a lot.


      Januka.



      --
      "Nothing can start to exist nor can cease to exist, only transformation is possible"

      Januka Attanayake
      Solid Earth Geophysics & Economics

      University of Connecticut
      Beach Hall U-2045
      354,Mansfield Rd;
      Storrs.CT 06269

      Tel: +1 860 486 0475 (Office)
      +1 860 486 3914 (Lab - P405)
      URL: http://sites.google.com/site/janukaattanayake/




      _______________________________________________
      sac-help mailing list
      sac-help<at>iris.washington.edu
      http://www.iris.washington.edu/mailman/listinfo/sac-help
11:49:30 v.22510d55