+ All Categories
Home > Documents > Utilizare 12

Utilizare 12

Date post: 21-Feb-2018
Category:
Upload: paul
View: 238 times
Download: 0 times
Share this document with a friend

of 37

Transcript
  • 7/24/2019 Utilizare 12

    1/37

  • 7/24/2019 Utilizare 12

    2/37

    M

    Back off, or I'll replace you with a small shell script.

    19.12.2011 2

  • 7/24/2019 Utilizare 12

    3/37

    S

    19.12.2011 3

    ACL

  • 7/24/2019 Utilizare 12

    4/37

    S

    19.12.2011 4

  • 7/24/2019 Utilizare 12

    5/37

    C

    F

    , , , , .

    P , , , , ,

    E

    19.12.2011 5

  • 7/24/2019 Utilizare 12

    6/37

    S

    S (I )

    C 12 S S 12.4, 12.5, 12.6, 12.9

    19.12.2011 6

  • 7/24/2019 Utilizare 12

    7/37

    R, ... 6

    I

    O ,

    E/

    V

    V

    G

    E

    19.12.2011 7

  • 7/24/2019 Utilizare 12

    8/37

    F

    A . (U)

    C

    filtru < input_file > output_file

    command1 | filtru | command2

    W PS O

    ( )

    ( )

    19.12.2011 8

  • 7/24/2019 Utilizare 12

    9/37

    , , ,

    C ? CTRL+D

    cat n

    ( )

    ( )

    19.12.2011 9

  • 7/24/2019 Utilizare 12

    10/37

    ,

    head -10, head, head -n 10

    10

    head -n -20

    20

    tail -10, tail, tail -n -10

    10

    tail -n +21

    21 ( 20)

    19.12.2011 10

  • 7/24/2019 Utilizare 12

    11/37

    S

    S TAB

    cut -f 1 < file

    cut -f 1-3 < file

    cut -f 1,4 -d : < /etc/passwd

    19.12.2011 11

  • 7/24/2019 Utilizare 12

    12/37

    T

    T

    tr a b < file

    tr a-z A-Z < file

    tr d < file

    S ifconfig | tr -s | cut -d -f 2

    tr -d -c A-Za-z < /dev/urandom | head -c 819.12.2011 12

  • 7/24/2019 Utilizare 12

    13/37

    ,

    S

    I

    sort -n file

    sort -r file

    sort -u file, sort file | uniq

    sort -k 3 file 3

    19.12.2011 13

  • 7/24/2019 Utilizare 12

    14/37

    C C

    wc -l

    wc -c

    wc -w

    19.12.2011 14

  • 7/24/2019 Utilizare 12

    15/37

    E

    F

    grep pattern file

    grep -r pattern /path/to/folder/

    grep -v pattern file

    grep -i pattern file

    grep --color=auto

    19.12.2011 15

  • 7/24/2019 Utilizare 12

    16/37

    P

    V ( 6)

    I

    I

    F

    19.12.2011 16

  • 7/24/2019 Utilizare 12

    17/37

    if grep dan /etc/passwd; then

    echo OK

    else

    echo NOK

    fi

    if test f /path/to/file; thenecho File exists

    fi

    if test $# -ne 1; then

    echo Usage: $0 file

    fi

    19.12.2011 17

  • 7/24/2019 Utilizare 12

    18/37

    (2)

    P

    0 = > !0 = >

    test -f file

    test -d file

    test string1 = string2 test num1 -eq num2

    test -z string1

    19.12.2011 18

  • 7/24/2019 Utilizare 12

    19/37

    ,

    for i in 1 2 3 4 5 6 7 8 9 10; do done

    for ((i = 1; i

  • 7/24/2019 Utilizare 12

    20/37

    ,

    while read a b c; do done < file

    IFS=:; while read uname pass uid extra; do

    if test $uid ge 1000; thenecho $uname

    fi

    done < /etc/passwd

    19.12.2011 20

    (2)

  • 7/24/2019 Utilizare 12

    21/37

    , (2)

    P ( )

    0

    (EOF)

    ( , )

    IFS

    19.12.2011 21

    F

  • 7/24/2019 Utilizare 12

    22/37

    F

    hello()

    {

    echo hello

    }

    ip_for_hostname()

    {

    host $1 | head -1 | cut d f 4

    }

    DEBUG(){

    test $_DEBUG eq 1 && $@

    }

    19.12.2011 22

    F (2)

  • 7/24/2019 Utilizare 12

    23/37

    F (2)

    M

    ()

    S ()

    P

    ,

    A

    $#, $1, $2, $@

    19.12.2011 23

  • 7/24/2019 Utilizare 12

    24/37

    sed n /abc/p

    sed n $=

    sed 10q

    sed s/ana/bogdan

    sed s/ana/bogdan/g

    19.12.2011 24

    (2)

  • 7/24/2019 Utilizare 12

    25/37

    (2)

    S

    C

    S +

    $= ( , )

    10q( 10, )

    s/ana/bogdan/g ( , )

    1,10s/ana/bogdan/g ( 10 , )

    /corina/s/ana/bogdan/g ( ,)

    S 19.12.2011 25

  • 7/24/2019 Utilizare 12

    26/37

    ifconfig | awk F [ \t]+ {print $5;}

    dpkg -l apache2* | grep ^ii | awk F [ \t]+ {print

    $2;}

    < /etc/passwd awk F : { if ($3 >= 1000) print $1;}

    19.12.2011 26

    (2)

  • 7/24/2019 Utilizare 12

    27/37

    (2)

    ++

    L C

    R $0

    $1, $2,

    NR ( )NF ( )

    19.12.2011 27

    R

  • 7/24/2019 Utilizare 12

    28/37

    R

    N // P, C, J, R, PHP .

    M ( , )

    N

    C

    ,

    N ( , *,

    )

    F

    ://../BFAQ19.12.2011 28

    U MAC

  • 7/24/2019 Utilizare 12

    29/37

    U MAC

    #!/bin/bash

    declare IFACE=eth1

    declare URL="http://anaconda.cs.pub.ro/~razvan/school/uso/lab/macs/putmac.php"

    declare MY_HWADDR

    function getmac(){

    MY_HWADDR=$(/sbin/ifconfig "$IFACE" | grep HW | awk -F '[ \t]+' '{print $5}')

    }

    function uploadmac()

    {wget -o /dev/null "$URL?mac=$MY_HWADDR" &> /dev/null

    }

    function main()

    {

    getmacuploadmac

    }

    main

    exit 0

    19.12.2011 29

    R

  • 7/24/2019 Utilizare 12

    30/37

    R #!/bin/bash

    BTDOWNLOADHEADLESS=/usr/bin/btdownloadheadless

    TORRENT_FILE="$1"

    DOWNLOAD_DIR="$2"

    function check_alive()

    {

    ps -ef | grep $BTDOWNLOADHEADLESS | grep $TORRENT_FILE &> /dev/null

    }

    check_alive

    if test $? -ne 0; then

    pushd . &> /dev/null

    cd $DOWNLOAD_DIR && nohup $BTDOWNLOADHEADLESS $TORRENT_FILE &>

    /dev/null &

    popd &> /dev/null

    fi

    exit 019.12.2011 30

    M

  • 7/24/2019 Utilizare 12

    31/37

    M

    #!/bin/bash

    IFS=","

    INPUT_FILE=lists/cdl_2010_list.txt

    while read username email name surname; do

    ./ldap_add $username $email $name $surname

    done < $INPUT_FILE

    exit 0

    19.12.2011 31

    M

  • 7/24/2019 Utilizare 12

    32/37

    M

    #!/bin/bash

    #passwd_file fisier cu useri gen /etc/passwd

    while read user skel_pass uid gid comm home shell; do

    save_dir="/home/$user/old_anaconda

    echo "$user $comm $home $shell

    useradd -m -d /home/$user -g users -s $shell -c "${comm}" $user

    mkdir ${save_dir}

    chown $user:users ${save_dir}bash ./rsync.sh $home ${save_dir}

    done < passwd_file

    19.12.2011 32

    S

  • 7/24/2019 Utilizare 12

    33/37

    S

    #!/bin/bash

    # get subject

    if test $# -ge 1; then

    subject="$1"

    else

    echo -en "Subject: "read subject

    fi

    # get file

    if test $# -ge 2; then

    file="$2"

    else

    echo -en "File: "

    read file

    fi

    # send mail to all LDAP accounts

    for i in $(ldapsearch -x mail | grep mail: | cut -d " " -f 2); do

    mail -s "$subject" $i < $file

    done

    exit 0

    19.12.2011 33

    W ?

  • 7/24/2019 Utilizare 12

    34/37

    W ?

    #!/bin/sed -f

    {

    s/\[\(http[^]]\+\)]/[[\1]]/g

    s///g

    s///gs///g

    s///g

    s//{{{/g

    s//}}}/g

    s//**/gs//**/g

    s///g

    s///g

    s/[ \t]*\(.*\)/* \1/g

    s/'''/**/gs/''/\/\//g

    s/{{{\[\[/[[/g

    s/\]\]}}}/]]/g

    s/\(\[\[http:[^ ]\+\) /\1|/g

    }

    19.12.2011 34

    C

  • 7/24/2019 Utilizare 12

    35/37

    35

    C

    IFS

    19.12.2011 35

    R L

  • 7/24/2019 Utilizare 12

    36/37

    36

    R

    ://../

    ://./LDP///

    ://./.

    ://../1.

    ://..///.

    ://../BFAQ

    19.12.2011 36

    T E

  • 7/24/2019 Utilizare 12

    37/37

    19.12.2011 37


Recommended