jeudi 1 mai 2014

SQL serveur - vérifiant en bash, si il existe une table SQL Server à l'aide de tsql et UnixODBC - Stack Overflow


Alright Ladies and gents here's my issue. Apparently a failure to find the table I'm attempting to write to does not return an exit code of 1, in fact it appears that no matter what I do I get a returned code of 0. does anyone know of a way to use tsql in conjunction with UnixODBC to check if a table exists. That's all I need to know if the table already exists I want to write to it, if the table does not exist than I'll run a different sql command to create the table and then write to it.


tsql -S 192.168.50.21\\MSSQLSERVER -U $username -P $password -o qh <<EOF
use NWSS
insert into "$nwnumber" (Date,IP) value('${Date[1]}','${IP[1]}')
go
quit
EOF

check=$?

if [ $check -eq 0 ]; then
echo "success"

elif [ $check -eq 0 ]; then
echo "failure"

fi


Alright Ladies and gents here's my issue. Apparently a failure to find the table I'm attempting to write to does not return an exit code of 1, in fact it appears that no matter what I do I get a returned code of 0. does anyone know of a way to use tsql in conjunction with UnixODBC to check if a table exists. That's all I need to know if the table already exists I want to write to it, if the table does not exist than I'll run a different sql command to create the table and then write to it.


tsql -S 192.168.50.21\\MSSQLSERVER -U $username -P $password -o qh <<EOF
use NWSS
insert into "$nwnumber" (Date,IP) value('${Date[1]}','${IP[1]}')
go
quit
EOF

check=$?

if [ $check -eq 0 ]; then
echo "success"

elif [ $check -eq 0 ]; then
echo "failure"

fi

0 commentaires:

Enregistrer un commentaire