Monday, September 18, 2006

FTP: Automated sessions via script

So you know how to use command line ftp clients, but you're not sure how to automate them with scripts.

WINDOWS (command-line)

ftp -s:script1.txt 11.11.11.11

script1.txt
username
password
ftp command1
ftp command2
quit

where username is the ftp username, password is their password. ftp command1 is any command line ftp commands like "get filename.zip" (download) or "put filename.rar" (upload).

Now its less important what the contents of the script are, and more important how to execute the script because once you know how, you can go use the commandline ftp client to run through whatever you want to automate, and make sure you have one command per line.

The only differences with the next command are that the hostname is embedded inside the script, and I replaced hostnames, usernames and passwords (etc) with more real examples.

ftp -s:script2.txt

script2.txt
open 192.168.0.123
gus
secretp123
put magicfile.zip
quit


LINUX

At the linux shell (command-line) type this command.
ftp < script2.txt

Because linux just uses i/o redirection, with the < symbol, one should use the format of script2 where the first line of the file is 'open [hostname]'.

USEFUL FTP COMMANDS
SERVER COMMANDS
# cd change directory on the remote SERVER
# cd .. change directory up one level on the remote SERVER
# pwd print the current directory you are within on the remote SERVER
# ls list files within the current directory on the remote SERVER
# binary prepare FTP to transfer binary files such as apps or images
# ascii prepare FTP to transfer ascii or text files such as .html files
# put copy a specific file from the local machine to the remote SERVER
# get copy a specific file from the remote SERVER to the local PC
# chmod change file permissions on a remote SERVER if you have access
# del delete a specific file on the remote SERVER
# bye end your FTP connection

LOCAL MACHINE
# lcd change directory on your local PC
# lcd .. change directory up one level on your local PC
# lpwd print the current directory you are within on your local PC


sources: http://support.microsoft.com/?kbid=96269 and http://www.reallylinux.com/docs/autoftp.shtml

Tuesday, September 12, 2006

DOS: Using winzip for command line

You want to automate compression and you remember pkunzip.exe and pkzip.exe of yesteryear. It turns out winzip can be used from the command line and embedded into a batch (.BAT) file for automation. (oooh automated backups).

The command format is:

 winzip32 [-min] action [options] filename[.zip] file(s)


-min this specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.

action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.

options
-r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.

-ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".

filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).

files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.

examples:

 winzip32.exe -min -a -r c:\myfiles\ c:\output.zip


this creates an output.zip with all the files in the c:\myfiles\ folder. if winzip isn't in your path, you may have to use "c:\program files\winzip32.exe" instead of winzip32.exe above,

 winzip32 -a "c:\My Documents\file1.doc" c:\output2.zip


this creates an output2.zip but note how the path must be enclosed in quotation marks because there is a space in it. Also winzip32.exe and winzip32 in the 2 examples are equivalent.

source: http://www.memecode.com/docs/winzip.html

Saturday, September 09, 2006

JBOSS: Deploying a win32 project on linux

When you copy a jboss project from a windows (eclipse) programming environment there are two important things to remember.

Modify permissions
1. chmod 775 $JBOSS_HOME/server/default/deploy/ProjectName.war

Fix WEB-INF
2. Change web-inf folder to uppercase WEB-INF

JBOSS: Running JBoss as a Service

Starting JBoss as a service:
http://wiki.jboss.org/wiki/Wiki.jsp?page=StartJBossOnBootWithLinux

More Linux tutorials (relative to startups)
http://yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html

LINUX: Useful commands

ps -aux|grep java //show processes containing 'java'
top //display processes list
passwd //change current users password
passwd gus123 //change password user gus123
service iptables stop //stops firewall from running
chkconfig iptables off//firewall won't start on boot

tail -f textfile//turns a log file thats being
//generated into a console
netstat -a //shows port usage
touch <file> //update timestamp of file
dd if=/dev/zero of=/dev/hda/ bs=512 count=1//wipe mbr
free -m //check mem usage
du -x --block-size=1024K | sort -nr | head -10
//10 biggest folders in current path
wc -l gives linecount


Memory Usage Tools useful
http://www.ss64.com/bash/ also useful

J2EE: Linux J2EE Server Setup

I ran the j2ee for linux installer and had issues:

[root@cs462-2-1 src]#./java_ee_sdk-5-linux.bin
Checking available disk space...
Checking Java(TM) 2 Runtime Environment...
Launching Java(TM) 2 Runtime Environment...
Deleting temporary files...


But then it would appear to hang. Well it wasn't really hanging. I've installed j2ee sdk before in linux on suse where there was a gui available, but this time I needed to do it via linux terminal (command line).

Solution: use the -console flag
[root@cs462-2-1 src]#./java_ee_sdk-5-linux.bin -console


Once we used the -console flag we were able to get past the "Deleting temporary files" output, and were give a console based installer UI that made us say yes to a license agreement, and choose the install path etc.