No file acces using a script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Siebbel
    New Member
    • Mar 2007
    • 13

    No file acces using a script

    Hello,

    I am pretty new with writing shell scripts and trying to use a script to perform some db2 commands on a CentOS 4 system. I get a problem when I put in my shell-file 'myscript.sh' the command:

    db2 -tf somefile.sql

    When executing, I get a DB2 error:

    DB21004E You cannot specify both an input file and a command when invoking the Command Line Processor.

    I discovered, using the debug command $ sh -x myscript.sh, that the shell adds some end of line symbols or something thet ruin the command, since the output gives:

    + db2 -tf ctb2.sql $'\r'

    I fugured this post would be better placed here than at the DB2 section. Can anyone help me how to get rid of this unwanted addition?

    Thanks in advance, Sietse
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Does the command "db2 -tf somefile.sql" work when you run it on the command line? Could you post your shell script? Please use [CODE ] [/CODE] tags around the script.

    Originally posted by Siebbel
    Hello,

    I am pretty new with writing shell scripts and trying to use a script to perform some db2 commands on a CentOS 4 system. I get a problem when I put in my shell-file 'myscript.sh' the command:

    db2 -tf somefile.sql

    When executing, I get a DB2 error:

    DB21004E You cannot specify both an input file and a command when invoking the Command Line Processor.

    I discovered, using the debug command $ sh -x myscript.sh, that the shell adds some end of line symbols or something thet ruin the command, since the output gives:

    + db2 -tf ctb2.sql $'\r'

    I fugured this post would be better placed here than at the DB2 section. Can anyone help me how to get rid of this unwanted addition?

    Thanks in advance, Sietse

    Comment

    • Siebbel
      New Member
      • Mar 2007
      • 13

      #3
      Originally posted by Motoma
      Does the command "db2 -tf somefile.sql" work when you run it on the command line? Could you post your shell script? Please use [CODE ] [/CODE] tags around the script.

      Thanks for replying!

      The command works perfectly from the command line. It seems to have something to do with the additional characters that probably have a meaning I do not know. The script is very simple, just a procession of commands that could be run from the command line and do work from it, but I would like to automize it with a script. The total script looks like:
      (DB2 runs already and script is run with DB2 user DB2USER that owns DATABASE. The redirection of the output to db2.log was used for debugging, removing it gives the same output)

      Code:
      #!/bin/sh
      . /home/db2inst1/sqllib/db2profile >> db2.log
      db2 connect to DATABASE >> db2.log
      echo "1" >> db2.log
      db2 -tf somefile.sql
      echo "2" >> db2.log
      db2 terminate >> db2.log
      echo "3" >> db2.log
      The output in db2.log was:

      Code:
       Database Connection Information
      
       Database server        = DB2/LINUX 9.1.2
       SQL authorization ID   = DB2USER
       Local database alias   = DATABASE
      
      1
      DB21004E  You cannot specify both an input file and a command when invoking
      the Command Line Processor.
      2
      DB20000I  The TERMINATE command completed successfully.
      3
      The relevant output of the debug command 'sh -x myscript.sh' was:

      Code:
      ++ . /home/db2inst1/sqllib/userprofile
      + db2 connect to DATABASE $'\r'
      + echo 1 $'\r'
      + db2 -tf somefile.sql $'\r'
      + echo 2 $'\r'
      + db2 terminate $'\r'
      + echo 3 $'\r'
      I hope you have some ideas!

      Siebbel

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        There is only one idea I have.
        What shell are you using?

        Comment

        • Siebbel
          New Member
          • Mar 2007
          • 13

          #5
          Originally posted by Motoma
          There is only one idea I have.
          What shell are you using?
          As far as I know sh, but I don't know how to check that.

          S.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Typically, sh is just a symlink to your shell of choice. This link is created at login, by reading the setting from /etc/passwd.

            Try running the following:
            Code:
            cat /etc/passwd | grep <username>
            and replace <username> with the username of your account.
            At the end of the line you should see something like /bin/bash or /bin/ksh

            Comment

            • Siebbel
              New Member
              • Mar 2007
              • 13

              #7
              I am working with user root, this is what the command returned:

              Code:
              root:x:0:0:root:/root:/bin/bash
              operator:x:11:0:operator:/root:/sbin/nologin
              So I guess it is indeed bash I am working with. Doesn't make things much clearer I'm afraid...?

              S.

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                I visited this page and took a look at the error code, as well as the command line options.
                My last idea is to remove the -t from the command, only specifying the -f flag.

                Sorry I couldn't help more.

                Comment

                • Siebbel
                  New Member
                  • Mar 2007
                  • 13

                  #9
                  That didn't do the trick unfortunately.. . Thanks for your help anyway.

                  S.

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by Siebbel
                    That didn't do the trick unfortunately.. . Thanks for your help anyway.

                    S.
                    You might want to try asking around on the db2 forum.

                    Comment

                    Working...