0

I made a script to connect to my sql server. when I copy my script into my terminal it works fine.

I connect to my sql server with a raspberrypi using Tsql

but when I put my script into a file to run it automatic I get an error.

First my script:

tsql -H Server -U Username -P Password 
Go
Use master

paste it into my shell

 root@raspberrypi:~# tsql -H Server -U Username -P Password
Missing argument -p, looking for default instance ... found default instance, port 1433
locale is "nl_NL"
locale charset is "ISO-8859-1"
using default charset "ISO-8859-1"
1> GO
1> use master
2> go
1>

I put exactly the same script into the file data.sh But it won't work.

root@raspberrypi:~# ./data.sh
Missing argument -p, looking for default instance ... found default instance, port 1433
locale is "nl_NL"
locale charset is "ISO-8859-1"
using default charset "ISO-8859-1"
1>

Can anyone help me with this problem

thanks

2 Answers 2

2

See this answer. For your data.sh script to work you need to pass the SQL statements into the tsql program. As you have it above, there is no input to the tsql program, so it just prints the prompt.

Try this in data.sh:

tsql -H Server -U Username -P Password <<EOF
    GO
    use master
    GO
EOF
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your reply unfortunately it won't work it look like he use the command but there is no result or ouput root@raspberrypi:~# ./databasecopy.sh Missing argument -p, looking for default instance ... found default instance, port 1433 locale is "nl_NL" locale charset is "ISO-8859-1" using default charset "ISO-8859-1" 1> 1> 2> 1> root@raspberrypi:~#
There is no results or output for the "Go" and "use master" commands, so the output in your comment matches what is in your first example where you paste into the shell. Try putting a SQL SELECT statement that produces results in the script and see if that works.
Sorry I forgot to tell that because of the reason it will not give output i changed the script an add a create database. but no database is created
OK, I don't know why it's not working for you. Sorry.
0

You are probably using named pipes. Try adding -L [instance_name].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.