Quantcast
Channel: Linux on the mainframe
Viewing all articles
Browse latest Browse all 18

A piece of ftp automatization

$
0
0

Often I have to copy the same files to a new linux guest. For that reason I setup a linux server with services like NFS, FTP, HTTP etc. To copy files from the server to the client there are a lot of possibilities. I'm just taking two of them in this example - CURLS and FTP - combined with a small bash script - a kind of a small piece of ftp automatization. Be aware I'm not covering any security tasks! I'm just working in a test environment.

Curl is a really powerful and versatile tool. Please, see more and in detail under http://curl.haxx.se .

What I'm going to do?

  1. First become to be root and change to the directory /usr/local/bin.
  2. Then I'm copying the script 'getfiles' and a datafile 'ftp.data' which contains userid, password, path to files and filenames which have been to copy. After copying I'have to make the script 'getfiles' executable.
  3. Run the script.

So from the ftp-server on 10.199.10.50 (SLES11FT) we'd like to get the files below and copy them into /usr/local/bin/. Furthermore the script will check/create a directory 'download' , copy files into it and copy '.alias' into the root directory. After downloading the files, rename them for using i.e. remove .txt or maybe add a dot (in case of the alias) and modify them to your needs. 

 
 Filename# Description
 Directory /configs 
getfiles# a script including ftp automatization
ftp.data# the data file including userid, password, files to download
bs # script to create scripts
turnoffservices# script to turnoff unnecessary services
systeminfo # script to get some systeminfo of a linuxguest

.alias

# some defined aliases
 
Directory /app_sources
nmon_mainframe_sles11# nmon application for SLES11 
dstat-0.7.2.tar # statistic application 
htop-0.9.tar.gz # a better alternative for top, the source code which we have to compile and install 
s 390-tools-1.17.0.tar # some specific s390x tools

  


add1)

lxadd01@lxadd01:~> su -
Password:
Directory: /root
Thu Jan 10 09:51:55 CET 2013
lxadd01:~ # cd /usr/local/bin/
lxadd01:/usr/local/bin # ll
total 8.0K
303310 4.0K drwxr-xr-x 11 root root 4.0K Nov 1 14:09 ..
303311 4.0K drwxr-xr-x 2 root root 4.0K Jan 10 08:32 .
lxadd01:/usr/local/bin #

add2)

lxadd01:/usr/local/bin # curl ftp://sles11/configs/getfiles -o getfiles ftp://sles11/configs/ftp.data -o ftp.data && chmod +x getfiles

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
110 884 110 884 0 0 185k 0 --:--:-- --:--:-- --:--:-- 863k
175 175 175 175 0 0 329k 0 --:--:-- --:--:-- --:--:-- 329k

lxadd01:/usr/local/bin # ll
total 16K
303310 4.0K drwxr-xr-x 11 root root 4.0K Nov 1 14:09 ..
106499 4.0K -rwxr-xr-x 1 root root 884 Jan 10 09:58 getfiles
106500 4.0K -rw-r--r-- 1 root root 175 Jan 10 09:58 ftp.data
303311 4.0K drwxr-xr-x 2 root root 4.0K Jan 10 09:58 .


Another way is to use ftp going directly to the appropriate directory 'configs/'.
The option -i turns off the interactive prompting during multiple file transfers.

lxadd01:/usr/local/bin # ftp -i 10.199.10.50:/configs/
Connected to 10.199.10.50.
220 (vsFTPd 2.0.7)
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
200 Switching to Binary mode.
250 Directory successfully changed.
ftp> mget getfiles ftp.data
local: getfiles remote: getfiles
229 Entering Extended Passive Mode (|||36666|)
150 Opening BINARY mode data connection for getfiles (884 bytes).
100% |***********************************************************************************| 884 9.80 MB/s 00:00 ETA
226 File send OK.
884 bytes received in 00:00 (3.13 MB/s)
local: ftp.data remote: ftp.data
229 Entering Extended Passive Mode (|||21185|)
150 Opening BINARY mode data connection for ftp.data (175 bytes).
100% |***********************************************************************************| 175 3.14 MB/s 00:00 ETA
226 File send OK.
175 bytes received in 00:00 (459.40 KB/s)
ftp> bye
221 Goodbye.
lxadd01:/usr/local/bin # chmod +x getfiles
lxadd01:/usr/local/bin # ll
total 16K
106500 4.0K -rw-r--r-- 1 root root 175 Oct 28 11:23 ftp.data
303310 4.0K drwxr-xr-x 11 root root 4.0K Nov 1 14:09 ..
106499 4.0K -rwxr-xr-x 1 root root 884 Jan 10 08:30 getfiles
303311 4.0K drwxr-xr-x 2 root root 4.0K Jan 10 10:08 .

Now, let's run the script 'getfiles' and show the files within /usr/local/bin

add3)

lxadd01:/usr/local/bin # getfiles
/usr/local/bin
Connected to 10.199.10.50.
220 (vsFTPd 2.0.7)
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
200 Switching to Binary mode.
250 Directory successfully changed.
530 Can't change from guest user.
Login failed.
Interactive mode off.
local: bs remote: bs
229 Entering Extended Passive Mode (|||38956|)
150 Opening BINARY mode data connection for bs (1542 bytes).
100% |***********************************************************************************| 1542 30.01 MB/s 00:00 ETA
226 File send OK.
1542 bytes received in 00:00 (6.80 MB/s)
local: turnoffservices remote: turnoffservices
229 Entering Extended Passive Mode (|||29743|)
150 Opening BINARY mode data connection for turnoffservices (296 bytes).
100% |***********************************************************************************| 296 7.42 MB/s 00:00 ETA
226 File send OK.
296 bytes received in 00:00 (1.37 MB/s)
local: systeminfo remote: systeminfo
229 Entering Extended Passive Mode (|||31437|)
150 Opening BINARY mode data connection for systeminfo (2020 bytes).
100% |***********************************************************************************| 2020 74.09 MB/s 00:00 ETA
226 File send OK.
2020 bytes received in 00:00 (13.28 MB/s)
local: .alias remote: .alias
229 Entering Extended Passive Mode (|||61025|)
150 Opening BINARY mode data connection for .alias (195 bytes).
100% |***********************************************************************************| 195 1.89 MB/s 00:00 ETA
226 File send OK.
195 bytes received in 00:00 (558.44 KB/s)
250 Directory successfully changed.
250 Directory successfully changed.
local: nmon_mainframe_sles11 remote: nmon_mainframe_sles11
229 Entering Extended Passive Mode (|||12162|)
150 Opening BINARY mode data connection for nmon_mainframe_sles11 (229643 bytes).
100% |***********************************************************************************| 224 KB 83.65 MB/s 00:00 ETA
226 File send OK.
229643 bytes received in 00:00 (78.80 MB/s)
local: dstat-0.7.2.tar remote: dstat-0.7.2.tar
229 Entering Extended Passive Mode (|||59173|)
150 Opening BINARY mode data connection for dstat-0.7.2.tar (583680 bytes).
100% |***********************************************************************************| 570 KB 115.26 MB/s 00:00 ETA
226 File send OK.
583680 bytes received in 00:00 (111.72 MB/s)
local: htop-0.9.tar.gz remote: htop-0.9.tar.gz
229 Entering Extended Passive Mode (|||42027|)
150 Opening BINARY mode data connection for htop-0.9.tar.gz (418767 bytes).
100% |***********************************************************************************| 408 KB 109.53 MB/s 00:00 ETA
226 File send OK.
418767 bytes received in 00:00 (106.92 MB/s)
221 Goodbye.
Found /root/downloads/...

lxadd01:/usr/local/bin # ll
total 1.3M
106505 232K -rwxr-xr-x 1 root root 225K Mar 31 2009 nmon_mainframe_sles11
106507 416K -rw-r--r-- 1 root root 409K Mar 30 2011 htop-0.9.tar.gz
106501 4.0K -rwxr-xr-x 1 root root 1.6K Jun 21 2011 bs
106502 4.0K -rwxr-xr-x 1 root root 296 Jun 21 2011 turnoffservices
106506 576K -rw-r--r-- 1 root root 570K Jul 9 2012 dstat-0.7.2.tar
106504 4.0K -rw-r--r-- 1 root root 195 Oct 10 08:43 .alias
106503 4.0K -rwxr-xr-x 1 root root 2.0K Oct 10 14:11 systeminfo
106500 4.0K -rw-r--r-- 1 root root 175 Oct 28 11:23 ftp.data
303310 4.0K drwxr-xr-x 11 root root 4.0K Nov 1 14:09 ..
106499 4.0K -rwxr-xr-x 1 root root 884 Jan 10 08:30 getfiles
303311 4.0K drwxr-xr-x 2 root root 4.0K Jan 10 10:12 .


 
The file ftp.data listing:

user ftp sles11ft

prompt
mget bs turnoffservices systeminfo .alias
cd ..
cd app_sources
mget nmon_mainframe_sles11 dstat-0.7.2.tar htop-0.9.tar.gz s390-tools-1.17.0.tar
bye

The script listing of 'getfiles':

#! /bin/bash
# Script:'getfiles' from Daniel Schwarzentruber, created on Wed, 18. Jul 2012
benid=$(whoami)
[ $benid != "root" ] && echo "You have to be 'root'. Pls, switch and start 'getfiles' again. Txs!" && su - && exit 1
Pfad=$(pwd) && echo $Pfad
cd /usr/local/bin

if [ -z ftp.data ]
then
echo "ftp.data not found! Pls, copy it to the directory /usr/local/bin" && exit 1
fi

ftp -n 10.199.10.50:/configs/ < /usr/local/bin/ftp.data

chmod +x bs turnoffservices systeminfo nmon_mainframe_sles11
downdir=/root/downloads/
if [ -a $downdir ]
then
echo "Found $downdir..."
cd /root/downloads/
else
echo "No directory 'downloads' found! Creating it...."
cd /root
mkdir downloads
fi
cp /usr/local/bin/* /root/downloads/
cp /usr/local/bin/.alias /root/
cd /usr/local/bin
exit 0

The post A piece of ftp automatization appeared first on Linux on the mainframe.


Viewing all articles
Browse latest Browse all 18

Trending Articles