ASTRONOMSKI KROŽEK Gimnazije Šentvid, psql, ftp, html, procedura - vaje


VAJA - KAKO PSQL, ftp, html, ... iz terminala, linux

Se dopolnjuje!!!!!!!



  1. ----- spodaj procedura test.sh---- pozenem ./test.sh (se prej odscitim za izvajanje chmod +x test.sh)
    #!/bin/sh
     
    PSQL=/usr/local/pgsql/bin/psql
     
    export PGUSER=peterm
    export PGPASSWORD=patern
     
    $PSQL bazatest -c " delete from vodbila_tek;"
    $PSQL bazatest -c "\\copy vod_bil_tek from '/home/et_p/zmvnos.txt' using delimiters ';'"
    $PSQL bazatest -c "\\copy vod_bil from '/home/et_p/zmarhiv.txt' using delimiters ';'"
    $PSQL bazatest  -H -P footer -f '/home/internet/tabelaWB_.txt' > 'tabelaWB_.html'
    $PSQL porabniki  -H -P footer  -f '/home/internet/temp.txt' > 'temp.html'
     
    cd /home/peterm
     
    cat << EndOfFile >/tmp/ftpscr.$$
    user peterm patern
    cd higro/txt
    put temp.html
    put tabelaWB_.html
    EndOfFile
     
    ftp -n meta.rak-lj.si  v.v
    ali na ekran
    [peterm@baza delo]$ psql bazatest -c " select * from vodbila_tek where id_parr=4;"
    id_parr | as | vc | d1 | rt| fr | dg
    ----+--------------+---------------+-------------+-------------------+-----------------+------------------
      4 |            7 | 1950-05-18    | 1992-01-01  |                   |                 |
      4 |           51 | 1950-05-18    | 1992-01-01  |                   |                 |
      4 |           52 | 1950-05-18    | 1992-01-01  |                   |                 |
      4 |           60 | 1950-05-18    | 1992-01-01  |                   |                 |
    (4 rows)
    
     
    Datum 25.8.2003 
    
    
    
    
    ------------------------------------
    
    ------------------------------------------------------------
    29) KAKO FTP
    -----------------------------
    FTP LINUX
    
    - prenasam datoteko test1.txt na drug ftp server ftp.inerge.si
    
    1) Deluje
    
    [janez@server programi]$ vi ftp_inerge.sh
    user slane D23iprj
    put test1.txt
    [janez@server programi]$ chmod + ftp_inerge.sh
    [janez@server programi]$ ftp -n ftp.inerge.si < ftp_inerge.sh
    
    
    - se stran za spodnjo proceduro
    http://www.inlumineconsulting.com:8080/website/scripting.ftp.html
    2) Bolje kot 1
    [janez@server programi]$ vi ftpinerge.sh
    #!/bin/sh
    HOST='ftp.inerge.si'
    USER='slane'
    PASSWD='D23iprj'
    FILE='test1.txt'
    
    cd /home/janez/programi
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    put $FILE
    quit
    END_SCRIPT
    exit 0
    ----------------------------------------------------------
    Opomba:
    kdaj tudi        ftp -n $HOST <<END_SCRIPT
    nadomestimo z    ftp -z nossl -n $HOST <<END_SCRIPT
    
    - kaj pomeni nossl?  - odpira localport 21 za TCP, glej spodaj
    nossl action=allow protocol=TCP dir=in localport=21
      
    ----------------------------------------------
    Komentar k zgornji proceduri:
    brez skoka na maticni direktorij (cd /home/janez/programi),
    ftp ne najde izvornega fajla za prenos,
    pred put ... pa lahko s cd ... spreminjas tudi
    ciljni direktorij na ciljnem strezniku, pri passive
    dodas se za ftp -n se -p, ce prenasa binarne datoteke, pa se 
    binary
    (put) get some.file
    
    [janez@server programi]$ chmod +x ftpinerge.sh
    - pozenem spodaj
    [janez@server programi]$ ./ftpinerge.sh
    ------------------------------------------------------
    Se spodnji spodnji nacin, kjer v prenos_iner.sh pozenem pl programcek, 
    ki scrpa podatke v nek fajl in naredi sh proceduro iner_ftp.sh, 
    ki se v prenos_iner.sh pozene takoj za pl programckom.
    ---------------------------
    ./prenos_iner.sh
    #!/bin/sh
    /home/janez/programi/iner_ftp1.pl
    chmod +x /home/janez/programi/iner_ftp.sh
    /home/janez/programi/iner_ftp.sh
    exit 0
    
    Opomba - iner_ftp.sh je po vsebini enaka proceduri ftpinerge.sh (zgoraj),
             le da to skripto naredi pl (perl procedura)
    
    v crontab pa jo pozenem s spodnjim ukazom ob 8. uri in 59 minut
    59 8 * * * /home/janez/programi/prenos_iner.sh >/home/janez/sql_vhodne/prenos_iner.log 2>/home/janez/sql_vhodne/prenos_iner.log
    
    
    kako rocno na ftp server
    ==============
    [janez@server programi]$ ftp -p ftp.inerge.si
    Connected to ftp.energetika-lj.si (212.118.92.43).
    220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 1 of 50 allowed.
    220-Local time is now 14:37. Server port: 21.
    220-This is a private system - No anonymous login
    220-IPv6 connections are also welcome on this server.
    220 You will be disconnected after 15 minutes of inactivity.
    Name (ftp.inerge.si:zvicar): slana
    331 User temperature OK. Password required
    Password:D23iprj
    230-User temperature has group access to:  50
    230 OK. Current directory is /
    Remote system type is UNIX.
    Using binary mode to transfer files.
    
    ftp> dir
    227 Entering Passive Mode (212,118,92,43,118,200)
    150 Accepted data connection
    drwxr-xr-x    2 1001     0            4096 Jan 16 09:48 .
    drwxr-xr-x    2 1001     0            4096 Jan 16 09:48 ..
    -rw-r--r--    1 1001     50             85 Jan 16 09:48 lj_t2007-01-15.txt
    226-Options: -a -l
    226 3 matches total
    ftp>
    ce das na drug streznik ime.x, potem
    put ime.x
    vzames
    binary ali ascii
    get ime.x
    
    
    
    
    
    
    
    
    
    -----------------
    
    
    se nekaj verzij
    
    #!/bin/sh
    HOST='ftp.users.qwest.net'
    USER='yourid'
    PASSWD='yourpw'
    FILE='file.txt'
    
    ftp $HOST <<END_SCRIPT
    user $USER
    $PASSWD
    put $FILE
    quit
    END_SCRIPT
    exit 0
    -----------------------------------
    
    
    
    
    
    
    #!/bin/sh
    
    ftp -n << END_SCRIPT
    open $1
    user $2 $3
    put $4
    get $4 retrieval.$$
    bye
    END_SCRIPT
    
    if [ -f retrieval.$$ ]
    then
    	echo "FTP of $4 to $1 worked"
    	rm -f retrieval.$$
    else
    	echo "FTP of $4 did not work"
    fi
    
    
    --------------------------------------------------------------------------------
    
    
    
    #!/bin/sh
    USER=userid
    PASSWD=userpw
    ftp -n f2dev <<SCRIPT
    user $USER $PASSWD
    binary
    get some.file
    quit
    SCRIPT
    
    
    
    
    
    ---------------------------------------
    
    
    shell procedura, ki bere iz baze
    in v zanki zapisuje v datoteke
    -------------------------
    
    
    DATUM1=2009-01-01
    DATUM2=2009-12-31
    leto=2009
    
    #####################################################
    
    
    
    export PGUSER="uporabnik"
    export PGPASSWORD="pipecxx"
    
    
    #
    #  Padavinske postaje
    #
    
      for POSTAJA in 116 122 123 127 167 175 226 228 229 235 237 253 255 258 259 260 262 345 351 475 571
        do
    
        FILENAME="PAD$leto-$POSTAJA.dat"
    
        QUERY="select datum, case when \"p5_padavine\">-1 then
               trunc(\"p5_padavine\"/10.0,1) else \"p5_padavine\" end  as RR
               from padavine_vhodna where postaja='$POSTAJA' and
                                        datum>='$DATUM1'and datum<='$DATUM2'
                                        order by datum "
    
    
    
    psql ime_baze -U uporabnik -h ime_racunalnika  -P footer -P null=null -c "$QUERY" >$FILENAME
    
         unix2dos $FILENAME
    
       done
    
    ~
    
    
    
    
    
    -----prenos_urnih1h.sh--------------------------------------------------------------------
    
    
    #!/bin/sh
    
    #feb. 2012, procedura za prenos urnih podatkov iz xy institucije
    #na xy server, urni podatki, podrocje  /home/podatki/elektro
    #iz serverja
    #HOST='xxx.3.yy.120'      USER='jakokosi'      PASSWD='piscek'
    #Procedura hkrati brise 10 dni stare fajle iz serverja  'xxx.3.yy.120'
    #--------------------------procedura se zazene vsako uro v 8 in 52 minuti
    
       HOST='xxx.3.yy.120'
       USER='jakokosi'      
       PASSWD='piscek'
    
    datum=$(date +"%Y-%m-%d") # vrne cel yyyy-mm-dd datum minus en dan,
    mesec=$(date +"%m") # vrne mesec
    leto=$(date +"%Y") # vrne leto
    dan=$(date +"%d") # vrne dan
    leto3=${leto:1:3} #substring zadnja tri mesta leta 2011 ge v 011
    leto2=${leto:2:3} #substring zadnja 2 mesta leta 2011 ge v 11
    ura=$(date +"%H") # vrne utc uro
    min=$(date +"%M") # vrne minute
    
    #echo $leto3 $leto2 $dan $ura $min
    # iscem ime datoteke: podatki_201202281350.tpv
    # podatki_LLLMMDDUU50.tpv
    # podatki_201202280050.tpv je za 27.02.2012;23:00:00,  gric;PADAVINE;27.02.2012;23:00:00;1h;0,0;1
    
    imef="podatki_"$leto$mesec$dan$ura"50.tpv"  # format podatki_LLLMMDDUU50.tpv
    
    
    datumd=$(date -d "-10 day" +"%Y-%m-%d") # vrne cel yyyy-mm-dd datum minus 10 dni
    mesecd=$(date -d "-10 day" +"%m") # vrne mesec
    letod=$(date -d "-10 day" +"%Y") # vrne leto
    dand=$(date -d "-10 day" +"%d") # vrne dan
    imefd="podatki_"$letod$mesecd$dand$ura"50.tpv"  # format *LLL.MMM, recimo *011.JAN
    
    
    
    
        cd /home/podatki/elektro
       # ftp -n $HOST 21  <<END_SCRIPT
       ftp -z nossl -n $HOST <<END_SCRIPT
       user $USER $PASSWD
       binary
       mget $imef
    
    quit
    END_SCRIPT
    
    
    
    
    OUT=$?    # prebere status ftp
    # sledi brisanje za deset dni nazaj, ukaz mdelete $imefd
    if [ $OUT -eq 0 ];then
     echo "ftp OK"
       ftp -z nossl -n $HOST <<END_SCRIPT
       user $USER $PASSWD
       binary
    status
    mdelete $imefd
    quit
    END_SCRIPT
    else
    echo "ftp Error: "$OUT
    fi
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  2. *

  3. *

  4. *

  5. *

Stevilo obiskov: veliko.


števci www.izmenjava.com

Za astronomski krožek: ZORKO Vičar


RFC-822: Zorko.Vicar@guest.arnes.si


Nazaj na domačo stran.