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

Hello,

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 "go.pl" 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 go.pl 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
Open WS_FTP
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 go.pl

go.pl contents--------------------------------------------

#!/bin/sh
cp ORDERS.txt /ORDERS.txt
mysql -u root -p db < /home/user/build.txt

------------------------------------------------------------

type root password

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

use db;

TRUNCATE TABLE `pages`;

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
rinse
repeat




MJL
mjinxedAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AmigoJackConnect With a Mentor Commented:
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:
c:
cd "\documents and settings\your_account\desktop"
ftp yourhost.com < 2.txt

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

>>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 :)
0
 
soapergemCommented:
I just don't see why this question is in the PHP section...you *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...
0
All Courses

From novice to tech pro — start learning today.