0

I need to automatize an sql script via bash. I'm asking about how to use bash variable in an sql command use by freeTDS. Here is my command and the code below :

   echo "Declare @montant int =$mobile ,@categorie varchar(12) = 'mobile',@nom varchar(50) = '%'+$filename+'%',@temps varchar(12) = $Tmobile

 Print @montant
 Print @categorie
 Print @nom
 Print @temps

 EXEC Test @montant, @categorie, @nom, @temps
 go
 " > tempfile

I use to load my sql function "Test" with parameters that come from my bash script. But i dunno why, the script don't recognize them. I already tried with the option -t on my command ("-t --mobile=$mobile").

    tsql -H $DB_HOSTNAME -p $DB_PORT -U $DB_USER -P $DB_PWD -D $DB_NAME -o fvq  
    < tempfile

The actual error is :

  Msg 126 (severity 15, state 1) from ARAGORN\GENESYS Line 2:
    "Invalid pseudocolumn "$filename"."
  Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 4:
    "Must declare the scalar variable "@montant"."
  Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 5:
    "Must declare the scalar variable "@categorie"."
  Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 6:
    "Must declare the scalar variable "@nom"."
  Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 7:
    "Must declare the scalar variable "@temps"."
  Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 9:
    "Must declare the scalar variable "@montant"."

Thanks !

  • The first error message looks like the `$filename` message substitution isn't working. I'd suggest manually editing tempfile until the `tsql` command works (use actual values the `declare` line in tempfile, instead of environment variables). Then you can worry about getting the bash environment to do its thing. – GregHNZ Aug 03 '17 at 08:25
  • Ye i already tried to replace this value but the problem is still the same ! – Axel Bonnafoux Aug 03 '17 at 08:35
  • 1
    Maybe post the resulting tempfile here? Might help. – GregHNZ Aug 03 '17 at 09:49

0 Answers0