Running Batch File From sql Server

  • Hello,

    I would like to run a command that would activate a batch file on my server.

    The problem its batch files job to transfer a file a unix system.

    My problem here is permissions. When I try it mt says I do not have the authority to do it.

    What can I do about this ?

    Thanks

    J

  • When you say a "batch file", there are at least two possibilities.

    One is you use the Scheduled Job feature of W2K. In there you can set the ID under which it runs and so provide a domain ID with suitable permissions. A simple way to determine if you have it right is log in under the ID you plan to use and run it manually. This has nothing to do with SQL.

    The second option is using SQL Agent to run it. Here the job step runs under the ID that SQL Agent is set up to run under. Changing that ID may give you correct permissions however it affects all SQL Agent jobs at once, so care must be taken in making the right choice as this may either break other things or open up security issues.

    There are possibly other alternatives as well.

  • You may need to configure SQL Agent Proxy account that has permissios to run your batch job.

  • You might want to try using RCP (Remote Copy) for your task. RPC

    has the advantage that you don't need to use passwords like you do

    with FTP. You also have to use a FULLY QUALIFIED DOMAIN NAME for the PC

    that will be performing the RCP commands. You can NOT use the IP address

    for the PC because the UNIX box will translate the name to an IP to verify

    that it is "talking" to the correct PC. It may take anywhere from 1 to 20

    or 30 minutes for the UNIX server to "recognize" the new .RHOSTS entry, so

    be patient.

    To find the FULLY QUALIFIED DOMAIN NAME for your PC, use the command

    NSLOOKUP 192.168.0.5

    Or what ever the Server IP address is.

    On the Unix Server, in the account that will receive/get files for the PC

    create a .RHOSTS (may need lower case name for Unix) ASCII file with

    a line (or lines) with the the FULLY QUALIFIED DNS NAME of the PC that will

    be used for the RCP like this:

    pc_server.mydomain.com username

    pc_server.mydomain.com username1

    pc_server1.mydomain.com username

    pc_server1.mydomain.com username1

    pc1.mydomain.com username

    pc2.mydomain.com username

    Notice the SPACE (or TAB) between the PC name and the UserName.

    Rem RCP (Remote Copy) Batch Commands To/From a Windows Server/Unix Server

    Rem Change to the Correct Drive (you can use fully qualified drive:\path

    Rem on the PC, but the command lines can get quite long.

    C:

    Rem Change to the correct SubDirectory on that will send/receive files

    cd c:\mydir

    Rem

    Rem RCP /? for help and command switches

    Rem

    Rem This line TO the Unix Server for ASCII files

    rcp -a myfile.txt unix_server.mydomain.com.username:myfile.txt

    Rem rcp -a myfile.txt unix_server.mydomain.com.username:/some_dir/myfile.txt

    Rem This line FROM the Unix Server for ASCII files

    rcp -a unix_server.mydomain.com.username:myfile.txt .

    Rem

    Rem This line TO the Unix Server for Binary files

    rcp -b myfile.bin unix_server.mydomain.com.username:myfile.bin

    Rem rcp -a myfile.bin unix_server.mydomain.com.username:/some_dir/myfile.bin

    Rem This line FROM the Unix Server for Binary files

    rcp -b unix_server.mydomain.com.username:myfile.bin .

    Now for some other mentions pertaining to RCP. You CAN RCP between

    UNIX or VAX servers (as long as the .RHOSTS file is in place)

    You CAN NOT RCP from a Unix machine to a PC, so don't even waste your time.

    The way I do this is to create Batch files on the PC for things I need to

    RCP on a regualar basis. The batch file name should obviously indicate what

    the file does.

    Since Command Windows close automatically when running a batch file,

    I open a command window, navigate to the directory where the file lives,

    and run the RCP command manually. IF the RCP command runs successfully,

    (check for the presence of the file on the Unix box), then I save the

    batch file and I'm ready for full automation.

    Some explanation of the RCP Command:

    rcp -a myfile.txt unix_server.mydomain.com.username:myfile.txt

    This command says to RCP an ASCII file, myfile.txt to the Unix server

    as the user in USERNAME, place the file in the Root directory of USER.

    Files can be RENAMED on the fly with the command:

    rcp -a myfile.txt unix_server.mydomain.com.username:some_file.sav

    IF the UNIX username is the SAME as the PC username, then you can

    use this command:

    rcp -a myfile.txt unix_server.mydomain.com:myfile.txt

    IF UNIX squawks about capitalization, then you can use QUOTES and make

    sure the quoted part is the correct capitalization:

    rcp -a myfile.txt unix_server.mydomain.com."username:myfile.txt"

    I hope this helps your quest for automation.

    Butch

    Edited by - ButchH on 12/20/2003 11:22:55 AM

    Edited by - ButchH on 12/20/2003 11:24:16 AM


    Butch

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply