There are instances where we might need to run some default scripts on a specified server once SQLCMD gets connected. It can be achieved in just three steps as explained below:
Step 1: Create a script file which you wanted to fire when SQLCMD gets connected to your SQL Server.
For keeping the example simple, I used the following line and saved it as SqlCmdStartUpScripts.sql
print 'Welcome today''s date is: ' + (convert(varchar, getdate()))
Step 2: Open DOS prompt and type set sqlcmdini=c:\vadivel\sql related\scripts\SqlCmdStartUpScripts.sql
Step 3: Then type SQLCMD and press Enter.
Refer the below screenshot for the sample output.