Create script that includes password and some commands - can I do it?

Posted on 2006-04-19
Last Modified: 2006-11-18

I'm working on a test server, not connected to network and not connected to Internet just doing some experimental work and I have to run these scripts like 100 times a day in my testing and tweaking and I want to automate some more of it. Right now I have a perl script named "" that has to be run as root but I can't log in as root so I have to log in as my user and then su root and then run that pulls some info from a txt file that dumpes into a MySQL DB. I wanna automate it ALL! Heck, if I could stick an icon on my desktop (Windows XP using PuTTY) that I could double click and it does all the logging in and SQL and everything and then self terminates when done, I'd be so happy I'd be a pig in mud. Here is what I do now - can someone help me simplify this repetitive process?

Generate data to ORDERS.ASC
Rename file to ORDERS.txt
Choose connection and click connect
Copy ORDERS.txt from my desktop to /home/user/ORDERS.txt
Close WS_FTP
Open Putty and choose my connection and click open
type user name
type password
type su root
type password
type perl contents--------------------------------------------

cp ORDERS.txt /ORDERS.txt
mysql -u root -p db < /home/user/build.txt


type root password

build.txt contents----------------------------------------

use db;


load data infile "/ORDERS.txt" into table pages fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';

delete from pages where item_description like '%freight%';
delete from pages where item_description like '%applied tax%';

UPDATE `pages` SET `mod_date` = NOW();


type exit
type exit

generate new data

Question by:mjinxed
    LVL 6

    Expert Comment

    I just don't see why this question is in the PHP *could* probably rewrite all your scripts to execute as PHP files (assuming you have PHP on your test server), but if you need to develop a script that will automate Windows processes, that's more about writing a BAT file than a PHP file, I think...
    LVL 12

    Accepted Solution

    create file 1.bat

    >>Generate data to ORDERS.ASC
    whatever this means, make a command out of it and add it into 1.bat

    >>Rename file to ORDERS.txt
    add these lines into file 1.bat:
    del orders.txt
    ren orders.asc orders.txt

    >>Open WS_FTP
    >>Choose connection and click connect
    >>Copy ORDERS.txt from my desktop to /home/user/ORDERS.txt
    >>Close WS_FTP
    add these lines into file 1.bat:
    cd "\documents and settings\your_account\desktop"
    ftp < 2.txt

    create a file 2.txt which will include all commands executed via ftp and add these lines
    cd /home/user
    delete orders.txt
    put orders.txt

    >>Open Putty and choose my connection and click open
    thats tricky, we need to use something non-gui, but ive never tested telnet. open up a commandline, type in "telnet" and use "help" along with the other commands to login into your host. the pattern is the same: create a file 3.txt and put in there all lines you need within the telnet-program, including the exit/quit-command. to your 1.bat you should add this line to execute telnet:
    telnet < 3.txt

    if you think youre overdone with this or want more answers, put a pointer question in "os / ms-dos" since .bat-programming relates to ms-dos :)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now